Click here to Skip to main content
15,896,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how do i use one dataset to store two tables and
get data from each table separately ?

here is my code: i jus want to use the dataset only once, and not code it like how i have did, is it possible....

C#
SqlConnection con = new SqlConnection(CS);
          con.Open();
          SqlDataAdapter da = new SqlDataAdapter("sp_GetEmpDesignation", con);
         SqlCommandBuilder cmdbuild = new SqlCommandBuilder(da);
          DataSet ds = new DataSet();
         da.Fill(ds,"EmpDesignation");
          //BindingSource bgs = new BindingSource(ds, "EmpDesignation");
          //// bgs.DataSource = ds;

         BindingSource bs = new BindingSource(ds, "EmpDesignation");
         //dataGridView1.DataSource = bs;
         comboBoxDesg.DataSource = bs;
         comboBoxDesg.DisplayMember = "designation";
         comboBoxDesg.ValueMember = "desgid";

         SqlDataAdapter da1 = new SqlDataAdapter("GetDepartment", con);
         SqlCommandBuilder cmdbuild1 = new SqlCommandBuilder(da1);
         DataSet ds1 = new DataSet();
         da1.Fill(ds1,"Department");
         BindingSource bs1 = new BindingSource(ds1, "Department");
         comboBoxDept.DataSource = bs1;
         comboBoxDept.DisplayMember = "department";

         //SqlDataAdapter dac = new SqlDataAdapter("sp_GetEmpDesignation", con);
         con.Close();
Posted
Updated 24-Nov-11 23:06pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900