我可以使用一个数据集来存储两个表吗 [英] can i use one dataset to store two tables
本文介绍了我可以使用一个数据集来存储两个表吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用一个数据集存储两个表和
分别从每个表中获取数据?
这是我的代码:我只是想只使用一次数据集,而不是像我以前那样编码它,有可能....
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....
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();
推荐答案
检查这些链接,
http://csharp.net-informations.com/dataset/csharp-dataset-tutorial.htm [^ ]
http://msdn.microsoft.com/zh-CN /library/system.data.dataset(v=vs.71).aspx [ http://msdn.microsoft.com/en-us/library/8bw9ksd6.aspx [ ^ ]
我希望这将有助于回答您的问题,
如果有帮助,请将其标记为答案
谢谢
check these link,
http://csharp.net-informations.com/dataset/csharp-dataset-tutorial.htm[^]
http://msdn.microsoft.com/en-us/library/system.data.dataset(v=vs.71).aspx[^]
http://msdn.microsoft.com/en-us/library/8bw9ksd6.aspx[^]
i''m hoping that it will help to answer your question,,
mark this as answer if it helps you
thanks
这篇关于我可以使用一个数据集来存储两个表吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文