D
djc
I am playing with the (new to me) sqlDataSource class. I used it to bind
data from a database table into a listbox with no code, worked great. Now I
need to do an INSERT for every item in a listbox. I used to just code the
ado stuff myself in .net 1.1. For example creating connection object,
creating sqlCommand object, parameters, etc... I would just create the ado
stuff, then loop through the listbox changing the sqlcommand parameter
values and execute the command (ExecuteNonQuery) each time through the loop.
Easy enough. Now I just went to try the same technique using the
sqlDataSource and it seems I can't.
For example I thought I could just do something like:
foreach (ListItem li in lstKeyPhrases.Items)
{
SqlDataSource1.InsertParameters["FK_MainID"] =
(int)Session["theAutoID"];
SqlDataSource1.InsertParameters["Keyphrase"] = li.Value;
SqlDataSource1.Insert();
}
I was thinking this would open connection do all the ado.net stuff and close
the connection just like the simple filling of a listbox scenario. This
won't compile. It seems you are not able to modify parameter values on the
fly? So are you not supposed to use an sqlDataSource for this scenario?
just do it the way I did before (net 1.x)?
data from a database table into a listbox with no code, worked great. Now I
need to do an INSERT for every item in a listbox. I used to just code the
ado stuff myself in .net 1.1. For example creating connection object,
creating sqlCommand object, parameters, etc... I would just create the ado
stuff, then loop through the listbox changing the sqlcommand parameter
values and execute the command (ExecuteNonQuery) each time through the loop.
Easy enough. Now I just went to try the same technique using the
sqlDataSource and it seems I can't.
For example I thought I could just do something like:
foreach (ListItem li in lstKeyPhrases.Items)
{
SqlDataSource1.InsertParameters["FK_MainID"] =
(int)Session["theAutoID"];
SqlDataSource1.InsertParameters["Keyphrase"] = li.Value;
SqlDataSource1.Insert();
}
I was thinking this would open connection do all the ado.net stuff and close
the connection just like the simple filling of a listbox scenario. This
won't compile. It seems you are not able to modify parameter values on the
fly? So are you not supposed to use an sqlDataSource for this scenario?
just do it the way I did before (net 1.x)?