set value of SqlDataSource parameter

R

Roger Jordan

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
 
J

jp2msft

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.
}
 
R

Roger Jordan

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 said:
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 said:
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
 
J

jp2msft

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 said:
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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top