How to add 2 tables in dataset ?


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);


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

//Second table

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

SqlDataAdapter da1 = new SqlDataAdapter(cmd1);


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

return ds;





Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.