473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

to sqlDataSource or not - scenario

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").Default Value = "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/lib...rtcommand.aspx
http://msdn2.microsoft.com/en-us/lib...inserting.aspx

which way to go?

any input on these 2 questions would be greatly appreciated. Thanks.
Nov 9 '06 #1
2 1966
This is just "opinion" so take it with a grain of salt. I like the
SqlDataSource and especially the ObjectDataSource controls. However, I
believe they were provided to "dummify" - enabling developers to make things
happen without (in many cases) having to write any code. If you feel
comfortable rolling your own, its a good bet you can do what you need to do
more efficiently, without having to go through the learning curve.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"djc" wrote:
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").Default Value = "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/lib...rtcommand.aspx
http://msdn2.microsoft.com/en-us/lib...inserting.aspx

which way to go?

any input on these 2 questions would be greatly appreciated. Thanks.
Nov 9 '06 #2
djc
Thanks for the input Peter. I am comfortable rolling my own in this
particular scenario, but not always. Do you know if using the SqlDataSource
for this scenario *would* behave as I suspect? (several iterations of
opening and closing the database unnecessarily)

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:B5**********************************@microsof t.com...
This is just "opinion" so take it with a grain of salt. I like the
SqlDataSource and especially the ObjectDataSource controls. However, I
believe they were provided to "dummify" - enabling developers to make
things
happen without (in many cases) having to write any code. If you feel
comfortable rolling your own, its a good bet you can do what you need to
do
more efficiently, without having to go through the learning curve.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"djc" wrote:
>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").Defaul tValue = "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/lib...rtcommand.aspx
http://msdn2.microsoft.com/en-us/lib...inserting.aspx

which way to go?

any input on these 2 questions would be greatly appreciated. Thanks.

Nov 9 '06 #3

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

Similar topics

0
by: ayende | last post by:
I've the following scenario, a web page that dispaly a GridView using SqlDataSource define thus: <asp:SqlDataSource ID="BoardTypes" runat="server" ConnectionString='<%$...
5
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...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
3
by: zapov | last post by:
Hi! Did anyone successfully managed to use some custom ADO.NET provider with SqlDataSource? I'd like to connect to some other database than MSSQL (like MySQL, Firebird or PostgreSQL) but I'm...
3
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...
4
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...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
3
by: djc | last post by:
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...
2
by: Julien Sobrier | last post by:
Hello, I have 2 SqlDataSource on the same page that retrieve the same column names: <asp:SqlDataSource ID="SqlStructure" runat="server" SelectCommand="SELECT a, b FROM c WHERE d = 0 /> ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.