Home All Groups Group Topic Archive Search About

can i use dynamic variable inside a dataadapter and bind to datagrid

Author
28 Mar 2005 8:04 AM
jijis
Hi

I want to use a sql designed in the dataadapter and I want to pass a
variable so it can retrieve related data by using "WHERE" clause in the sql
statement.

Author
28 Mar 2005 2:23 PM
Elton Wang
You can use command object to pass parameter to sql query.

SqlConnection conn = new SqlConnection(CONNECTIN_STRING);
SqlCommand command = conn.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = "SELECT * FROM Table_Name WHERE
field_Name = @parameter";
command.Parameters.Add("@parameter",value);
SqlDataAdapter dap = new SqlDataAdapter(command);

HTH

Elton Wang
elton_w***@hotmail.com

>-----Original Message-----
>Hi
>
>I want to use a sql designed in the dataadapter and I
want to pass a
>variable so it can retrieve related data by using "WHERE"
clause in the sql
Show quoteHide quote
>statement.
>
>
>.
>
Author
28 Mar 2005 2:24 PM
Brock Allen
So add a parameter to the DataAdapter.SelectCommand.Parameters collection:

DataAdapter1.SelectCommand.CommandText = "select * from foo where bar = @bar";
DataAdapter1.SelectCommand.Parameters.Add("@bar", "some value");

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> Hi
>
> I want to use a sql designed in the dataadapter and I want to pass a
> variable so it can retrieve related data by using "WHERE" clause in
> the sql statement.
>