473,609 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.S electQuery = "SELECT * FROM Employees WHERE LastName =
@LastName"
SqlDataSource.P arameter(@LastN ame) = "Smith"

The 'accepted answer' to this question from Experts Exchange was to use the
DefaultValue property like so:
SqlDataSource.S electParameters ("LastName").De faultValue = "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 1990
This is just "opinion" so take it with a grain of salt. I like the
SqlDataSource and especially the ObjectDataSourc e 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.S electQuery = "SELECT * FROM Employees WHERE LastName =
@LastName"
SqlDataSource.P arameter(@LastN ame) = "Smith"

The 'accepted answer' to this question from Experts Exchange was to use the
DefaultValue property like so:
SqlDataSource.S electParameters ("LastName").De faultValue = "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*******@yaho o.nospammin.com wrote in message
news:B5******** *************** ***********@mic rosoft.com...
This is just "opinion" so take it with a grain of salt. I like the
SqlDataSource and especially the ObjectDataSourc e 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
SqlDataSourc e 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(@Last Name) = "Smith"

The 'accepted answer' to this question from Experts Exchange was to use
the
DefaultValue property like so:
SqlDataSource. SelectParameter s("LastName").D efaultValue = "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
1007
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='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT BoardTypes.BoardTypeId, BoardTypes.BoardTypeName, BoardTypes.BoardTypeDescription, BoardTypes.ValidityEndDate, BoardTypes.ValidityStartDate, OrganizationUnit.Name AS OrganizationalUnitName FROM BoardTypes INNER...
5
4469
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 ControlParameter <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XYZ %>"
8
5029
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 select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for my GridView/SqlDataSource combinations. I typically select from a view and update the corresponding...
3
5065
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 having problems making this work. Inside connectionStrings I added my name, provider and connectionString but for some reason SqlDataSource is trying to use System.Data.SqlClient even if my provider is different.
3
6396
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 sqldatasource. Conflictdetection set to compareallvalues. Oldvaluesparameterformatstring set to original_{0} tblA has 2 fields. ID and MyText. Deletecommand="Delete from tblA where ID=@original_ID"
4
3439
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 VS.NET IDE. I've made a user control -- let's call it MyUserControl.ascx -- with a DataGrid and an SqlDataSource. The SqlDataSource that loads content by categoryID. I've defined a property on MyUserControl.ascx called ContentCategoryID.
5
7681
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, the compiler believes an SQL db is being accessed ("An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does...
3
2948
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 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...
2
2081
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 /> <asp:SqlDataSource ID="SqlSons" runat="server" SelectCommand="SELECT a, b FROM c WHERE d = 74" /> The problem is that Eval("a") always return the value from SqlStructure.
0
8130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8076
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8573
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8222
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8406
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6057
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5510
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2531
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.