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 (ExecuteNonQuer y) 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.I tems)
{
SqlDataSource1. InsertParameter s["FK_MainID"] =
(int)Session["theAutoID"];
SqlDataSource1. InsertParameter s["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)? 3 2957
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$******** ******@TK2MSFTN GP03.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 (ExecuteNonQuer y) each time through the loop. Easy enough. Now I just went to try the same technique using the sqlDataSourc e and it seems I can't.
For example I thought I could just do something like:
foreach (ListItem li in lstKeyPhrases.I tems)
{
SqlDataSource1. InsertParameter s["FK_MainID"] =
(int)Session["theAutoID"];
SqlDataSource1. InsertParameter s["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)?
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 misunderstandin g 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@trndny 01...
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$******** ******@TK2MSFTN GP03.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 (ExecuteNonQuer y) each time through the loop. Easy enough. Now I just went to try the same technique using the sqlDataSour ce and it seems I can't.
For example I thought I could just do something like:
foreach (ListItem li in lstKeyPhrases.I tems) { SqlDataSource1. InsertParameter s["FK_MainID"] = (int)Session["theAutoID"]; SqlDataSource1. InsertParameter s["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)?
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@trndny 01...
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$******** ******@TK2MSFTN GP03.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 (ExecuteNonQuer y) each time through the loop. Easy enough. Now I just went to try the same technique using the sqlDataSour ce and it seems I can't.
For example I thought I could just do something like:
foreach (ListItem li in lstKeyPhrases.I tems) { SqlDataSource1. InsertParameter s["FK_MainID"] = (int)Session["theAutoID"]; SqlDataSource1. InsertParameter s["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)? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 %>"
|
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"
|
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 control (Stored
Procedure with 2 input parameters). The GridView contains 3 columns
(QuestionNumber, QuestionText, and a TemplateField). The TemplateField is
initially empty at design time and is populated with other UserControls which
are...
|
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.
|
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 ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT cedula,nombre,tipo FROM clientes WHERE nombre LIKE '%'
+ @nombre +...
| |
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.
How do I get this working?
--
Thank you kindly,
Dan Sikorsky BA, BSCE, MCS
|
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 Framework 2.0.
My problem is I want to get the last generated Identity field from a
table =IDENT_current('tblname')=. I can put this command in the Select
Command but when I try execute it it wants more parameters. Example:...
|
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 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...
|
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 database from
Access to SQL Server. So I go in to the SQLDataSource and modify it to
connect to the SQL Server database. No problem. However, the
DetailsView control does not seem to pick up the changes. When I click
on the little shortcut menu (not...
|
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...
|
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,...
| |
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |