how to connect multiple table with dataset

Posted by Klbaiju under ADO.NET on 7/3/2014 | Points: 10 | Views : 556 | Status : [Member] | Replies : 1
Hi,

In my application ,iam using stored procedure.and that stored procedure return values from 2 tables

means 2 select queries.

my problem is ,i want to connect this with dataset.

i tried like this

using (SqlCommand cmd = new SqlCommand("Sp_selconductorTest", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@tourdate", tDate);
cmd.Parameters.AddWithValue("@busid", busid);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds1 = new DataSet();
DataSet ds2 = new DataSet();
da.Fill(ds1.Tables[0]);

da.Fill(ds2.Tables[1]);

}


this showing error.

if i try

da.Fill(ds1);


it displays first table values.

How to take value of second table?

Regards,
Baiju




Responses

Posted by: Jayakumars on: 7/4/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

Dataset is collection of datatable so
use your code like this

da.Fill(ds1.Tables[0]);

here added single dataset added multiple datatable

so we have access like this

Code
==========
ds.table[0]
ds.table[1]




Mark as Answer if its helpful to you

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response