473,763 Members | 5,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDataSource - parameters?

I have the following code:

SqlDataSource ds = new SqlDataSource() ;
ds.ConnectionSt ring =
WebConfiguratio nManager.Connec tionStrings["AnketaDBConnec tionString"].ToString();
ds.UpdateComman d = "ad_SetAnsw er";
ds.UpdateComman dType = SqlDataSourceCo mmandType.Store dProcedure;
ds.UpdateParame ters.Add(new Parameter("@Que stionID"));
ds.UpdateParame ters.Add(new Parameter("@Ans wer"));
foreach (RepeaterItem li in Repeater1.Items )
{
int QuestionID =
int.Parse(((Htm lInputHidden)li .FindControl("h dQuestionID")). Value);
int Answer =
int.Parse(((Rad ioButtonList)li .FindControl("r blAnswers")).Se lectedValue);
ds.UpdateParame ters["@QuestionI D"].DefaultValue =
QuestionID.ToSt ring();
ds.UpdateParame ters["@Answer"].DefaultValue = Answer.ToString ();
ds.Update();
}
On the very first loop iteration I get the following:
Procedure or Function 'ad_SetAnswer' expects parameter '@QuestionID',
which was not supplied.

What's up with that? How do I work with parameters in SqlDataSource?
In fact, is there a better way to model SqlCOmmand cmd = ...;
cmd.ExecuteNonQ uery();?

Nov 17 '05 #1
1 3399
I suggest you to use SqlCommand instead.
It will be easier..

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

<re******@gmail .com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I have the following code:

SqlDataSource ds = new SqlDataSource() ;
ds.ConnectionSt ring =
WebConfiguratio nManager.Connec tionStrings["AnketaDBConnec tionString"].ToString();
ds.UpdateComman d = "ad_SetAnsw er";
ds.UpdateComman dType = SqlDataSourceCo mmandType.Store dProcedure;
ds.UpdateParame ters.Add(new Parameter("@Que stionID"));
ds.UpdateParame ters.Add(new Parameter("@Ans wer"));
foreach (RepeaterItem li in Repeater1.Items )
{
int QuestionID =
int.Parse(((Htm lInputHidden)li .FindControl("h dQuestionID")). Value);
int Answer =
int.Parse(((Rad ioButtonList)li .FindControl("r blAnswers")).Se lectedValue);
ds.UpdateParame ters["@QuestionI D"].DefaultValue =
QuestionID.ToSt ring();
ds.UpdateParame ters["@Answer"].DefaultValue = Answer.ToString ();
ds.Update();
}
On the very first loop iteration I get the following:
Procedure or Function 'ad_SetAnswer' expects parameter '@QuestionID',
which was not supplied.

What's up with that? How do I work with parameters in SqlDataSource?
In fact, is there a better way to model SqlCOmmand cmd = ...;
cmd.ExecuteNonQ uery();?

Nov 17 '05 #2

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

Similar topics

5
4480
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 %>"
3
6412
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"
0
1616
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...
4
3450
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.
3
8923
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 +...
0
1024
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:...
3
2957
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...
1
4273
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...
2
2468
by: Brad Isaacs | last post by:
Good evening friends, I have added a Drop Down List box control to my web form. I am using the web.config connection string to access my SQL Server 2000 db. Inside that db I have a table named Provinces. The table contains 3 fields : LanguageID ProvinceID
1
12323
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some poor soul. Situation: I want to do a lookup using a stored procedure for each value in a Row within a GridView. I use a lookup function in my code behind, evaluating the necessary bound fields. The problem is the SqlDataSource representing...
0
9563
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
9386
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
10145
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
9938
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
9822
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
7366
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
6642
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
3917
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
2
3523
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.