473,403 Members | 2,293 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,403 software developers and data experts.

set value of SqlDataSource parameter

Hello,

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

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 ParameterCollection (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 2303
Are you sure, Roger? I'm not able to find anything called SQLDataSource.

That being said:

using System.Data.SqlClient;

private void Scratch(string dbConn) {
string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
SqlConnection con = new SqlConnection(dbConn);
SqlCommand cmd = new SqlCommand(sqlDel, con);
cmd.Parameters.Add("@ID", SqlDbType.VarChar, 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.DeleteParameter:

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 ParameterCollection (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.WebControls.SqlDataSource
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*****@discussions.microsoft.comschrieb im Newsbeitrag
news:FA**********************************@microsof t.com...
Are you sure, Roger? I'm not able to find anything called SQLDataSource.

That being said:

using System.Data.SqlClient;

private void Scratch(string dbConn) {
string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
SqlConnection con = new SqlConnection(dbConn);
SqlCommand cmd = new SqlCommand(sqlDel, con);
cmd.Parameters.Add("@ID", SqlDbType.VarChar, 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.DeleteParameter:

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 ParameterCollection (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.WebControls.SqlDataSource
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*****@discussions.microsoft.comschrieb im Newsbeitrag
news:FA**********************************@microsof t.com...
Are you sure, Roger? I'm not able to find anything called SQLDataSource.

That being said:

using System.Data.SqlClient;

private void Scratch(string dbConn) {
string sqlDel = "DELETE FROM [testTable] WHERE [ID]=@ID";
SqlConnection con = new SqlConnection(dbConn);
SqlCommand cmd = new SqlCommand(sqlDel, con);
cmd.Parameters.Add("@ID", SqlDbType.VarChar, 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.DeleteParameter:

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 ParameterCollection (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
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: ...
2
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...
6
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...
0
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...
0
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...
4
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 -...
3
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...
4
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...
4
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.