Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLDatasource parameters

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.Add("@id", id);
// and also like this:
SqlDataSourceArticole.SelectParameters.Add("id", id);

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

like image 936
hhh3112 Avatar asked Sep 18 '25 15:09

hhh3112


2 Answers

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();
like image 130
darth_phoenixx Avatar answered Sep 20 '25 04:09

darth_phoenixx


You can update the value by:

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

Using the default value can work in this case.

HTH.

like image 31
Brian Mains Avatar answered Sep 20 '25 05:09

Brian Mains