D
djc
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 several items. The reason I'm
wondering if I should use an SqlDataSource object is overhead. For example,
prior to learning about the sqlDataSource I would just code the ado.net
procedure myself. For example, create connection object, create and
configure SqlCommand with parameters, open the connection once, perform
*all* the INSERT operations, then close the connection. If I use an
SqlDataSource object explicitly calling it's Insert command each time
through the listbox loop will it open and close the connection to the
database each time? or even worse, create a connection object, open it, and
close it, for each and every INSERT? If so I assume that would be very
undesireable.
2) Even if I don't use the sqlDataSource right now I need clarification on
this related topic. Someone else already asked this better than me so I'm
just copy/pasting this:
If I have a SqlDataSource with a @LastName parameter and want to assign a
value at runtime how do I do it without using Controls, Session Variables,
etc.
For instance what I expect is:
SqlDataSource.SelectQuery = "SELECT * FROM Employees WHERE LastName =
@LastName"
SqlDataSource.Parameter(@LastName) = "Smith"
The 'accepted answer' to this question from Experts Exchange was to use the
DefaultValue property like so:
SqlDataSource.SelectParameters("LastName").DefaultValue = "Smith"
This doesn't seem right to me? (or the original poster on EE). I dont want
to assign a 'default' value, I want to assign 'the' value. It does work but
should it be used?
The other way suggested to me was to use events as the links below show.
these 2 links provided to me by Andrey K illustrate using the OnInsert event
to change parameter values, and validate them
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insertcommand.aspx
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.inserting.aspx
which way to go?
any input on these 2 questions would be greatly appreciated. Thanks.
particular scenario. I need to loop through a listbox and perform an INSERT
sql operation for each item. Could be a few or several items. The reason I'm
wondering if I should use an SqlDataSource object is overhead. For example,
prior to learning about the sqlDataSource I would just code the ado.net
procedure myself. For example, create connection object, create and
configure SqlCommand with parameters, open the connection once, perform
*all* the INSERT operations, then close the connection. If I use an
SqlDataSource object explicitly calling it's Insert command each time
through the listbox loop will it open and close the connection to the
database each time? or even worse, create a connection object, open it, and
close it, for each and every INSERT? If so I assume that would be very
undesireable.
2) Even if I don't use the sqlDataSource right now I need clarification on
this related topic. Someone else already asked this better than me so I'm
just copy/pasting this:
If I have a SqlDataSource with a @LastName parameter and want to assign a
value at runtime how do I do it without using Controls, Session Variables,
etc.
For instance what I expect is:
SqlDataSource.SelectQuery = "SELECT * FROM Employees WHERE LastName =
@LastName"
SqlDataSource.Parameter(@LastName) = "Smith"
The 'accepted answer' to this question from Experts Exchange was to use the
DefaultValue property like so:
SqlDataSource.SelectParameters("LastName").DefaultValue = "Smith"
This doesn't seem right to me? (or the original poster on EE). I dont want
to assign a 'default' value, I want to assign 'the' value. It does work but
should it be used?
The other way suggested to me was to use events as the links below show.
these 2 links provided to me by Andrey K illustrate using the OnInsert event
to change parameter values, and validate them
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insertcommand.aspx
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.inserting.aspx
which way to go?
any input on these 2 questions would be greatly appreciated. Thanks.