600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > .net mysql参数化查询 ASP.NET中的mysql参数化查询

.net mysql参数化查询 ASP.NET中的mysql参数化查询

时间:2024-04-25 05:09:19

相关推荐

.net mysql参数化查询 ASP.NET中的mysql参数化查询

我正在处理参数化查询,但结果不正确

这是我的代码

public MySqlCommand Get_Login(string clinetID, string loginID, string password, string branchID)

{

MySqlCommand objCommand = new MySqlCommand(this.Query);

objCommand.Parameters.AddWithValue("@ClientID", clinetID);

objCommand.Parameters.AddWithValue("@LoginID", loginID);

objCommand.Parameters.AddWithValue("@Password", password);

objCommand.Parameters.AddWithValue("@BranchID", branchID);

mandType = CommandType.Text;

return objCommand;

}

而当调试时,这就是我在" objCommand"

Select u.groupid,p.PersonId, p.designationid,concat(p.salutation,p.FName,'

',p.MName,' ',p.LName) as PersonName,tb.Type

BrType,Id,p.subdepartmentid,ifnull(crossdept,'N') as

crossdept,p.departmentid,u.defaultpage,id,ifnull(p.crosslab,'N') as crosslab,

(select indoor_services from dc_Tp_organization where orgid='@ClientID') as

indoor_services,(select name from dc_Tp_organization where orgid='@ClientID') as

orgname,

(select default_route from dc_Tp_organization where orgid='@ClientID') as

default_route,p.BranchID BranchID,tb.Name BRName from dc_tp_personnel p left outer

join

dc_tu_userright u on u.personid=p.personid left outer join dc_tp_branch tb on

tb.BranchID=p.BranchID Where p.Active='Y' and p.LoginId = '@LoginID' and p.Pasword

='@Password' and p.BranchID='@BranchID'

我没有得到参数值

这是查询

objdbhims.Query ="Select u.groupid,p.PersonId,

p.designationid,concat(p.salutation,p.FName,' ',p.MName,' ',p.LName) as

PersonName,tb.Type BrType,Id,p.subdepartmentid,ifnull(crossdept,'N') as

crossdept,p.departmentid,u.defaultpage,id,ifnull(p.crosslab,'N') as crosslab,

(select indoor_services from dc_Tp_organization where orgid=@ClientID) as

indoor_services,(select name from dc_Tp_organization where orgid=@ClientID) as

orgname,(select default_route from dc_Tp_organization where orgid=@ClientID) as

default_route,p.BranchID BranchID,tb.Name BRName from dc_tp_personnel p left outer

join dc_tu_userright u on u.personid=p.personid left outer join dc_tp_branch tb on

tb.BranchID=p.BranchID Where p.Active='Y' and p.LoginId = @LoginID and p.Pasword

=@Password and p.BranchID=@BranchID";

this.Query声明了什么?

公共字符串Query {get {return StrQuery; }设置{StrQuery = value; }}

它基本上是从另一个类获取Query,然后将参数添加到该类的命令Object中

:)我的意思是填充该属性的查询是什么

@Secret Squirre:有问题

好的,请检查此链接,原因是因为您使用了错误的MySQL标识符,应为?而不是@

@秘密松鼠。 谢谢它的工作,我起初不能正确理解... :)

秘密松鼠在使用"?"时是正确的用于参数化变量。 MySQL对查询的内联sql变量使用" @",因此希望声明它们,例如从脚本或内联(选择子查询)声明的一部分进行声明。

您需要在查询中以及在命令中同时更改参数...的两个实例... Parameters.Add ...实例。

另外,我注意到了,也不确定是否要这样做,但是在您的WHERE子句中,您有"密码"(只有一个" s")与密码(两个" s")不知道是否是故意的。

最后一件事可能会有所帮助。由于某些参数与列名匹配,因此建议通过在列名和实际参数之间的FORCE区分中添加" x"之类的内容来稍微更改参数...

where... p.LoginID = ?xLoginID ...

并在命令参数中

objCommand.Parameters.AddWithValue("?xLoginID", loginID);

问题在于,参数用单引号引起来,将其转换为字符串文字。

要使其工作,请删除它们周围的单引号。例如。

Where p.Active = 'Y'

and p.LoginId = @LoginID

and p.Pasword = @Password

and p.BranchID = @BranchID

这对他有什么帮助?

p.Active = Y和p.LoginId = @LoginID和p.Pasword = @ Password和p.BranchID=@BranchID

@SecretSquirrel是什么意思,它对他有什么帮助? 尝试复制问题并尝试引用参数。 让Command对象可以找到您的参数。

@今草顿? 问题必须出在输入上,更改输出既无用也无用。 是的,很明显,SQL中的变量不应包含在引号中。 但是问题是查询是如何生成的。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。