如何设置sqldatasource参数的值?

the*_*ner 9 asp.net sqldatasource

我想设定的值sqldatasourceselectcommand参数@ClientID,如下面的代码,但它不工作了.

我的代码:

Dim strCommand = "SELECT caller_id, phone, name, email FROM callers WHERE client_id=@ClientID"

SqlDataSource2.SelectCommand = strCommand

SqlDataSource2.SelectParameters.Add("@ClientID", iClientID) 
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Pab*_*ruz 8

使其工作的诀窍是在添加之前删除您尝试使用的paremeter.以下改编版的代码应该有效:

' NOTE that there is no "@" sign when you use your parameters in the code
Parameter p = strCommandSqlDataSource2.SelectParameters["ClientID"]
strCommandSqlDataSource2.SelectParameters.Remove(p)
strCommandSqlDataSource2.SelectParameters.Add("ClientID", iClientID)
Run Code Online (Sandbox Code Playgroud)

在其使用的代码部分中命名参数时,不应使用"@"符号.您应该只在SQLCOMMAND字符串中使用它.

希望能帮助到你.


the*_*ner 2

没关系...配置数据源的参数以获取另一个控件的值..