How to add 2 tables in dataset ?


Hi

Dataset is used to hold the multiple tables. if we have to store multiple table on it, we can do like this

Declare the dataset as global

DataSet ds = new DataSet();

public DataSet fill()

{

//First table

SqlCommand cmd = new SqlCommand(“Select EmpName from tblEmp”, con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(ds.Tables.Add());

ds.Tables[0].TableName = “Test”;

//Second table

SqlCommand cmd1 = new SqlCommand(“Select EmpName from tblEmp1”, con);

SqlDataAdapter da1 = new SqlDataAdapter(cmd1);

da1.Fill(ds.Tables.Add());

ds.Tables[1].TableName = “Test1”;

return ds;

}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: