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

Discussion in 'ASP .Net Datagrid Control' started by jijis, Mar 28, 2005.

  1. jijis

    jijis Guest

    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.
     
    jijis, Mar 28, 2005
    #1
    1. Advertising

  2. jijis

    Elton Wang Guest

    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


    >-----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
    >statement.
    >
    >
    >.
    >
     
    Elton Wang, Mar 28, 2005
    #2
    1. Advertising

  3. jijis

    Brock Allen Guest

    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



    > 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.
    >
     
    Brock Allen, Mar 28, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Eshtry
    Replies:
    0
    Views:
    645
    Andy Eshtry
    Mar 1, 2004
  2. Steve Mauldin
    Replies:
    0
    Views:
    383
    Steve Mauldin
    Aug 27, 2004
  3. Andy Eshtry
    Replies:
    0
    Views:
    340
    Andy Eshtry
    Mar 1, 2004
  4. Andy Eshtry
    Replies:
    0
    Views:
    185
    Andy Eshtry
    Mar 1, 2004
  5. Andy Eshtry
    Replies:
    0
    Views:
    170
    Andy Eshtry
    Mar 1, 2004
Loading...

Share This Page