我想使用多个填充适配器方法填充单个数据集 [英] i want to fill single dataset using multiple fill adapter method
本文介绍了我想使用多个填充适配器方法填充单个数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好先生,
我想使用具有不同sp的multiple fill adapter method
Evey适配器填充单个dataset
.如何在单个数据集中插入10个sp值.
谢谢
以下是我的代码.
hello sir,
I want to fill single dataset
using multiple fill adapter method
Evey adapter having different sp . how can i insert 10 sp value in single dataset.
Thanks
Below is my code.
try
{
SqlConnection ObjconMwp = new SqlConnection(ConfigurationManager.ConnectionStrings["conMwp.Properties.Settings.ConnectionString"].ConnectionString);
// open connection
ObjconMwp.Open();
//ds2.Clear();
////wd1
SqlCommand cmd1 = new SqlCommand("spWDReport1",ObjconMwp);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@WD_Date",dtEP.Value);
DataSet ds1 = new DataSet();
SqlDataAdapter adp1 = new SqlDataAdapter(cmd1);
adp1.Fill(ds1);
////WD2
SqlCommand cmd2 = new SqlCommand("spWDReport2", ObjconMwp);
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.Parameters.AddWithValue("@WD_Date", dtEP.Value);
SqlDataAdapter adp2 = new SqlDataAdapter(cmd2);
//adp1.TableMappings.Add
adp2.Fill(ds1);
// //WD3
SqlCommand cmd3 = new SqlCommand("spWDReport3", ObjconMwp);
cmd3.CommandType = CommandType.StoredProcedure;
cmd3.Parameters.AddWithValue("@WD_Date", dtEP.Value);
SqlDataAdapter adp3 = new SqlDataAdapter(cmd3);
adp3.Fill(ds1);
////WD4
SqlCommand cmd4 = new SqlCommand("spWDReport4", ObjconMwp);
cmd4.CommandType = CommandType.StoredProcedure;
cmd4.Parameters.AddWithValue("@WD_Date", dtEP.Value);
SqlDataAdapter adp4 = new SqlDataAdapter(cmd4);
adp4.Fill(ds1);
// //WD5
SqlCommand cmd5 = new SqlCommand("spWDReport5", ObjconMwp);
cmd5.CommandType = CommandType.StoredProcedure;
cmd5.Parameters.AddWithValue("@WD_Date", dtEP.Value);
SqlDataAdapter adp5 = new SqlDataAdapter(cmd5);
adp5.Fill(ds1);
// //WD6
SqlCommand cmd6 = new SqlCommand("spWDReport6", ObjconMwp);
cmd6.CommandType = CommandType.StoredProcedure;
cmd6.Parameters.AddWithValue("@WD_Date", dtEP.Value);
SqlDataAdapter adp6 = new SqlDataAdapter(cmd6);
adp6.Fill(ds1);
////WD7
SqlCommand cmd7 = new SqlCommand("spWDReport7", ObjconMwp);
cmd7.CommandType = CommandType.StoredProcedure;
cmd7.Parameters.AddWithValue("@WD_Date", dtEP.Value);
SqlDataAdapter adp7 = new SqlDataAdapter(cmd7);
adp7.Fill(ds1);
////Ep1
SqlCommand cmd8 = new SqlCommand("spEPReport1", ObjconMwp);
cmd8.CommandType = CommandType.StoredProcedure;
cmd8.Parameters.AddWithValue("@EPDate", dtEP.Value);
SqlDataAdapter adp8 = new SqlDataAdapter(cmd8);
adp8.Fill(ds1);
////Ep2
SqlCommand cmd9 = new SqlCommand("spEPReport2", ObjconMwp);
cmd9.CommandType = CommandType.StoredProcedure;
cmd9.Parameters.AddWithValue("@EPDate", dtEP.Value);
SqlDataAdapter adp9 = new SqlDataAdapter(cmd9);
adp9.Fill(ds1);
////Ep3
SqlCommand cmd10 = new SqlCommand("spEPReport3", ObjconMwp);
cmd10.CommandType = CommandType.StoredProcedure;
cmd10.Parameters.AddWithValue("@EPDate", dtEP.Value);
SqlDataAdapter adp10 = new SqlDataAdapter(cmd10);
adp10.Fill(ds1);
////Ep4
SqlCommand cmd11 = new SqlCommand("spEPReport4", ObjconMwp);
cmd11.CommandType = CommandType.StoredProcedure;
cmd11.Parameters.AddWithValue("@EPDate", dtEP.Value);
SqlDataAdapter adp11 = new SqlDataAdapter(cmd11);
adp11.Fill(ds1);
////Ep5
SqlCommand cmd12 = new SqlCommand("spEPReport5", ObjconMwp);
cmd12.CommandType = CommandType.StoredProcedure;
cmd12.Parameters.AddWithValue("@EPDate", dtEP.Value);
SqlDataAdapter adp12 = new SqlDataAdapter(cmd12);
adp12.Fill(ds1);
////Ep6
SqlCommand cmd13 = new SqlCommand("spEPReport6", ObjconMwp);
cmd13.CommandType = CommandType.StoredProcedure;
cmd13.Parameters.AddWithValue("@EPDate", dtEP.Value);
SqlDataAdapter adp13 = new SqlDataAdapter(cmd13);
adp13.Fill(ds1);
////Ep7
SqlCommand cmd14 = new SqlCommand("spEPReport7", ObjconMwp);
cmd14.CommandType = CommandType.StoredProcedure;
cmd14.Parameters.AddWithValue("@EPDate", dtEP.Value);
SqlDataAdapter adp14 = new SqlDataAdapter(cmd14);
adp14.Fill(ds1);
objRpt.SetDataSource(ds1);
crystalReportViewer1.ReportSource = objRpt;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
推荐答案
SqlDataAdapter.Fill方法具有一个以DataTable作为参数的重载.您可以使用多个Fill命令来填充多个表,然后将这些表添加到单个数据集中.像这样的东西:
Hi,
The SqlDataAdapter.Fill methos has an overload that takes DataTable as parameter. You can use multiple Fill commands to fill multiple tables and then add these tables to single dataset. Something like :
DataSet ds = new DataSet();
DataTable dt = new DataTable("Employee");
SqlDataAdapter da = new SqlDataAdapter();
//Add some command
//Finally call fill
da.Fill(dt);
ds.Tables.Add(dt);
SqlDataAdapter da1 = new SqlDataAdapter();
DataTable dt1 = new DataTable("Department");
//Add some command
//Finally call fill
da1.Fill(dt1);
ds.Tables.Add(dt1);
希望对您有所帮助:)
Hope it helps :)
这篇关于我想使用多个填充适配器方法填充单个数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文