Binding to Datagrid

Discussion in 'ASP .Net Datagrid Control' started by jasmine, Dec 9, 2003.

  1. jasmine

    jasmine Guest

    hi friend

    I am developing web application in .NET using c#. I encounter a problem in binding the results to the datagrid. I have a storeprocedure that produce 2 results set. I need to read the results and bind it in a datagrid control. But i am able to bind only one result set eventhough i am using the datareader.next result(); Can any one of you help me? My code follows her

    SqlCommand cmd1 = new SqlCommand("Testpaper_DHistory",conn)
    cmd1.CommandType=System.Data.CommandType.StoredProcedure
    SqlParameter myparam = cmd1.Parameters.Add(new SqlParameter("@nric",SqlDbType.VarChar,20))
    myparam.Value = Session["userid"].ToString()
    SqlDataReader myreader = cmd1.ExecuteReader()
    d

    Grid1.DataSource=myreader
    Grid1.DataBind()

    while (myreader.NextResult())
    myreader.Close()
    conn.Close()

    Even I tried Grid1.Datasource = cmd1.ExecuteReader(); It is also not working.
    jasmine, Dec 9, 2003
    #1
    1. Advertising

  2. jasmine

    lostinet Guest

    you should join the two tables
    use SqlDataAdapter.Fill in to a DataSet ds first
    DataTable table1=ds.Tables[0];
    DataTable table2=ds.Tables[1];
    foreach(DataRow row in table2.Rows)
    {
    table1.ImportRow(row);
    }
    Grid1.DataSource=table1.DefaultView;
    Grid1.DataBind();

    "jasmine" <> дÈëÓʼþ
    news:...
    > hi friends
    >
    > I am developing web application in .NET using c#. I encounter a problem in

    binding the results to the datagrid. I have a storeprocedure that produce 2
    results set. I need to read the results and bind it in a datagrid control.
    But i am able to bind only one result set eventhough i am using the
    datareader.next result(); Can any one of you help me? My code follows here
    >
    > SqlCommand cmd1 = new SqlCommand("Testpaper_DHistory",conn);
    > cmd1.CommandType=System.Data.CommandType.StoredProcedure;
    > SqlParameter myparam = cmd1.Parameters.Add(new

    SqlParameter("@nric",SqlDbType.VarChar,20));
    > myparam.Value = Session["userid"].ToString();
    > SqlDataReader myreader = cmd1.ExecuteReader();
    > do
    > {
    > Grid1.DataSource=myreader;
    > Grid1.DataBind();
    > }
    > while (myreader.NextResult());
    > myreader.Close();
    > conn.Close();
    >
    >
    > Even I tried Grid1.Datasource = cmd1.ExecuteReader(); It is also not

    working.
    >
    lostinet, Dec 9, 2003
    #2
    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. Jordan
    Replies:
    2
    Views:
    2,517
    Jordan
    Feb 10, 2004
  2. Amit
    Replies:
    6
    Views:
    13,752
    Assimalyst
    Oct 24, 2006
  3. Replies:
    2
    Views:
    842
    Kevin Grover
    Oct 20, 2006
  4. JcFx
    Replies:
    0
    Views:
    265
  5. Vivek Nallur

    value binding and function binding

    Vivek Nallur, Sep 25, 2003, in forum: Ruby
    Replies:
    0
    Views:
    128
    Vivek Nallur
    Sep 25, 2003
Loading...

Share This Page