I have the following:
SqlConnection con = new SqlConnection(strConn);
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("SELECT [Key], [Value] FROM [data_LookupValues] where Category = 'CanadaProvinces' ", con);
myda.Fill(ds);
ddlState.DataSource = ds;
ddlState.DataTextField = "Value";
ddlState.DataValueField = "Key";
ddlState.DataBind();
I am stuck as I need to put a string value of CanadaProvinces within the SqlDataAdapter.
Is there a easy way of doing this? I get an error when I do it the way I have it.
The proper way would be to do a number of things:
usingblocksSqlCommandobject and use a parametrized query (instead of concatenating together your SQL)DataTableinstead of the much “heavier”DataSetCanadaProvinces)So your code should be something like this:
and then in your ASPX web’s code-behind, use something like this:
and be done with it. Now you can call your
FetchDatamethod to retrieve any possible category in your lookup table!