SQLDatasource Parameters

How can I set sql parameters for sqlDatasource in code? I try 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?

+3
source share
2 answers

Before setting the default value, make sure that you add selection options.

i.e.

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

You can update the value with:

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

Using the default value may work in this case.

NTN.

+2
source

Source: https://habr.com/ru/post/1791047/


All Articles