开发者

SQLDatasource parameters

开发者 https://www.devze.com 2023-02-09 07:16 出处:网络
How can i set sql parameters for an sqlDatasource in the code behind? I am trying like this: int id=1; SqlDataSource1.SelectCommand = \"SELECT * FROM categ WHERE id=@id\";

How can i set sql parameters for an sqlDatasource in the code behind? I am trying like this:

int id=1;
SqlDataSource1.SelectCommand = "SELECT * FROM categ WHERE id=@id";
SqlDataSourceArticole.SelectParameters.A开发者_StackOverflow中文版dd("@id", id);
// and also like this:
SqlDataSourceArticole.SelectParameters.Add("id", id);

but it doesn't work? What am i doing wrong?


Make sure you add the select parameters before trying to set their default value.

i.e.

SqlDataSourceArticole.SelectParameters.Add("@id", id);
SqlDataSourceArticole.SelectParameters["id"].DefaultValue = id.ToString();


You can update the value by:

SqlDataSourceArticole.SelectParameters["id"].DefaultValue = id.ToString();

Using the default value can work in this case.

HTH.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号