473,503 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sqlDataSource parameters question

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)?
Nov 8 '06 #1
3 2940
You should assign insert command parameter in an OnInserting event handler,
like it's described in

http://msdn2.microsoft.com/en-us/lib...rtcommand.aspx
http://msdn2.microsoft.com/en-us/lib...inserting.aspx

HTH,
Andrey.

"djc" <no***@nowhere.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
>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)?

Nov 9 '06 #2
djc
thanks Andrey. I read through it. I'm thinking I should just do it the way I
always have for this scenario... seems much more straight forward. I could
be misunderstanding here but it looks like using the OnInserting event
handler in the example from the article is used to add a new parameter where
I am looking to just modify values of existing parameters. I'm sure
something could be written to do what I need using the event but it seems
like overkill for such a simple task.

I found a different post that asks my question better than I did so I am
going to repost. I will also include the 'accepted answer' from this post
(from experts exchange) which is one way I was considering. checkout the new
post

Your input is appreciated. Thanks.

"Andrey Korneyev" <ak*******@nyc.rr.comwrote in message
news:xtx4h.6041$Tz.1346@trndny01...
You should assign insert command parameter in an OnInserting event
handler, like it's described in

http://msdn2.microsoft.com/en-us/lib...rtcommand.aspx
http://msdn2.microsoft.com/en-us/lib...inserting.aspx

HTH,
Andrey.

"djc" <no***@nowhere.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
>>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)?


Nov 9 '06 #3
djc
whoops... Sorry Andrey, I just realized you provided 2 links. I had only
read the first one. The second link cleary states to use this event to
'modify parameter values.' Thank you.

I am still going to post a second thread that will be slightly different. I
want to get some input on an alternative I came across that doesn't really
seem right to me (but is really really simple) and I have a follow up
question specific to my scenario.

check out the new post. Your input is very much appreciated.
thanks.

"Andrey Korneyev" <ak*******@nyc.rr.comwrote in message
news:xtx4h.6041$Tz.1346@trndny01...
You should assign insert command parameter in an OnInserting event
handler, like it's described in

http://msdn2.microsoft.com/en-us/lib...rtcommand.aspx
http://msdn2.microsoft.com/en-us/lib...inserting.aspx

HTH,
Andrey.

"djc" <no***@nowhere.comwrote in message
news:e$**************@TK2MSFTNGP03.phx.gbl...
>>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)?


Nov 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4459
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
3
6386
by: Jim Andersen | last post by:
Just to let you know, and to help any future sorry sods who gets trapped in the same black hole...... You can't just copy/move a working sql-statement into a stored procedure. Working with a...
0
1592
by: Giovanni | last post by:
I was wondering if someone would be able to help me with the following: Simply put, I have built an ASP.NET 2.0 WebUserControl (UC1). UC1 contains: A GridView which is bound to an SQLDataSource...
4
3434
by: | last post by:
I'm building some user controls. I very much like how you can build custom properties to be bound to a user control, and how instances of that control will show those custom properties in the...
3
8915
by: Daniel R. H. | last post by:
Hi, I'm having problems to get the value of a Querystring into the SelectCommand of a SQLDataSource, here's my code: ---------------------------------------------- <asp:SqlDataSource...
9
2203
by: Dan Sikorsky | last post by:
When I hit the Test Query button in the SqlDataSource design, all the rows come back. But when I run the website, without any changes, in the IDE, the GridView tied to the SqlDataSoure is empty. ...
0
1006
by: JR | last post by:
I have a question with SqlDataSource controls. I have a SqlDataSource control that has a select, insert and update parameters defined. This is running with Visual Studio 2005 Team system and Net...
2
1982
by: djc | last post by:
1) I am wondering if I should be using an sqlDataSource object for my particular scenario. I need to loop through a listbox and perform an INSERT sql operation for each item. Could be a few or...
1
4256
by: Corey B | last post by:
I have a page with a DetailsView control and a SQLDataSource control. The SQLDataSource control is connected to an Access database. Everything works fine. Now I want to change the back end...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.