473,765 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

set value of SqlDataSource parameter

Hello,

I'm using a SQLDataSource with name SqlDataSource1, the DeleteCommand
has a parameter, with isdefined in SqlDataSource.D eleteParameter:

DELETE FROM [testTable] WHERE [ID]=@ID

The parameter is not bind to any control, cookie or something like this.
How do I set a value for this parameter before calling the
SQLDataSource1. Delete() method?

As SqlDatasource1. DeleteParamters is of type ParameterCollec tion (and not
SqlParameter) there is no "value" property.

I like to use it in a for ()-Statement to delete a number of elements, so i
each step I want to set the parameter and then call the delete() method.

I'm using MS SQL Server 2005 and Visual Studio 2005 with C#.

Thanks for you help
Roger


Jul 16 '08 #1
3 2319
Are you sure, Roger? I'm not able to find anything called SQLDataSource.

That being said:

using System.Data.Sql Client;

private void Scratch(string dbConn) {
string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
SqlConnection con = new SqlConnection(d bConn);
SqlCommand cmd = new SqlCommand(sqlD el, con);
cmd.Parameters. Add("@ID", SqlDbType.VarCh ar, 8).Value = "123";
// now do what you want with it.
}
"Roger Jordan" wrote:
Hello,

I'm using a SQLDataSource with name SqlDataSource1, the DeleteCommand
has a parameter, with isdefined in SqlDataSource.D eleteParameter:

DELETE FROM [testTable] WHERE [ID]=@ID

The parameter is not bind to any control, cookie or something like this.
How do I set a value for this parameter before calling the
SQLDataSource1. Delete() method?

As SqlDatasource1. DeleteParamters is of type ParameterCollec tion (and not
SqlParameter) there is no "value" property.

I like to use it in a for ()-Statement to delete a number of elements, so i
each step I want to set the parameter and then call the delete() method.

I'm using MS SQL Server 2005 and Visual Studio 2005 with C#.

Thanks for you help
Roger


Jul 16 '08 #2
Yes, I'm sure.
It's a System.Web.UI.W ebControls.SqlD ataSource
This component could be bind to a grid (thats the case in my appliction) or
any other data sensitive control. But addionally I want to manual call the
delete method.
"jp2msft" <jp*****@discus sions.microsoft .comschrieb im Newsbeitrag
news:FA******** *************** ***********@mic rosoft.com...
Are you sure, Roger? I'm not able to find anything called SQLDataSource.

That being said:

using System.Data.Sql Client;

private void Scratch(string dbConn) {
string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
SqlConnection con = new SqlConnection(d bConn);
SqlCommand cmd = new SqlCommand(sqlD el, con);
cmd.Parameters. Add("@ID", SqlDbType.VarCh ar, 8).Value = "123";
// now do what you want with it.
}
"Roger Jordan" wrote:
>Hello,

I'm using a SQLDataSource with name SqlDataSource1, the DeleteCommand
has a parameter, with isdefined in SqlDataSource.D eleteParameter:

DELETE FROM [testTable] WHERE [ID]=@ID

The parameter is not bind to any control, cookie or something like this.
How do I set a value for this parameter before calling the
SQLDataSource1 .Delete() method?

As SqlDatasource1. DeleteParamters is of type ParameterCollec tion (and not
SqlParameter ) there is no "value" property.

I like to use it in a for ()-Statement to delete a number of elements, so
i
each step I want to set the parameter and then call the delete() method.

I'm using MS SQL Server 2005 and Visual Studio 2005 with C#.

Thanks for you help
Roger



Jul 16 '08 #3
That explains a lot! I don't use web controls.

So, did my solution guide you along your way? Obviously, you would have to
taylor it to a web control, but you get the idea, right?

"Roger Jordan" wrote:
Yes, I'm sure.
It's a System.Web.UI.W ebControls.SqlD ataSource
This component could be bind to a grid (thats the case in my appliction) or
any other data sensitive control. But addionally I want to manual call the
delete method.
"jp2msft" <jp*****@discus sions.microsoft .comschrieb im Newsbeitrag
news:FA******** *************** ***********@mic rosoft.com...
Are you sure, Roger? I'm not able to find anything called SQLDataSource.

That being said:

using System.Data.Sql Client;

private void Scratch(string dbConn) {
string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
SqlConnection con = new SqlConnection(d bConn);
SqlCommand cmd = new SqlCommand(sqlD el, con);
cmd.Parameters. Add("@ID", SqlDbType.VarCh ar, 8).Value = "123";
// now do what you want with it.
}
"Roger Jordan" wrote:
Hello,

I'm using a SQLDataSource with name SqlDataSource1, the DeleteCommand
has a parameter, with isdefined in SqlDataSource.D eleteParameter:

DELETE FROM [testTable] WHERE [ID]=@ID

The parameter is not bind to any control, cookie or something like this.
How do I set a value for this parameter before calling the
SQLDataSource1. Delete() method?

As SqlDatasource1. DeleteParamters is of type ParameterCollec tion (and not
SqlParameter) there is no "value" property.

I like to use it in a for ()-Statement to delete a number of elements, so
i
each step I want to set the parameter and then call the delete() method.

I'm using MS SQL Server 2005 and Visual Studio 2005 with C#.

Thanks for you help
Roger




Jul 16 '08 #4

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

Similar topics

3
11284
by: michelle | last post by:
I am trying to get an output value from a stored procedure using sqlDataSource in asp.net 2.0. But I only get a null value for the output. Can someone please help? The sqlDataSource: <asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings: ConnectionString1 %>" SelectCommand="UserLkp" SelectCommandType="StoredProcedure"
2
3858
by: K B | last post by:
Hi, I have a gridview with a SqlDataSource. One of the parameters I need to use in the update is the logged on person. The parameter was created automatically, but I need to override the value with the "new" person doing the update (e.g., sUser). How can I do this please? <asp:Parameter Name="LastUpdatedBy" Type="String" />
6
8273
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im trying to load the ddl with a list of dates from another table keyed on GridView row field that only apply to this row. Any suggestions would be appreciated.
0
3335
by: Ed | last post by:
All of a sudden my previously working code started throwing this error. from the SqlDatasource. I am using C# and Asp.net 2.0. Getting the following error: You have specified that your delete command compares all values on SqlDataSource 'sdsAddEdit', but the dictionary passed in for values is empty. Pass in a valid dictionary for delete or change your mode to OverwriteChanges.
0
1601
by: Managed Code | last post by:
Hello, I have a status and definition table. The status table's current status field relates the ID field of the definition table. I am trying to retrieve the definitions that are associated only with the master_id for the status table's current status. After having some trouble databinding I found a solution using a hidden label to save the value I need for my select parameter. The error I am receiving is 'ddlStatus' has a...
4
7253
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which - "Modified" of type DateTime - is hidden since it should not be edited by a user. The system handles the update for this column. So, I have hidden (Visible=false) this column on the grid. In order to access the value in this field, I have created a...
3
8017
by: Ken Cox [Microsoft MVP] | last post by:
I've been going around and around on this one. I can't believe that it is "by design" as Microsoft says. Here's the situation: In *declarative* syntax, I'm trying to create a default datetime value for a SqlDataSource parameter. (I know how to insert this parameter in code. I want to use declarative markup.) Here's the declarative markup with ???????? indicating where I'm stumped.
4
9790
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the SqlDataSource to allow the GridView to be editable. I have now been able to get the GridView to display data...
4
2907
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data. I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
0
9398
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
10007
jinu1996
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...
1
9951
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
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
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();...
0
5275
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...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
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.