从三个变量填充数据表,或将三个表的数据放入一个变量,然后生成数据表 [英] Filling the datatable from three variable or putting the three table's data into one variable and then producing the data table
问题描述
I have three table and I want to put the three table's data in one variable and from that variable i will produce the datatable and then want to write the data in CSV file.
I am Following this step..
DataClasses1DataContext
DataClasses1DataContext
da = 新 DataClasses1DataContext ();
da=new DataClasses1DataContext();
//ApplicationDataDataContext da =新的ApplicationDataDataContext();
//ApplicationDataDataContext da = new ApplicationDataDataContext();
var
a = 来自 x in da.Controls
a = from x in da.Controls
选择
x. CT_GUID_Type;
var
b = 来自 y in da.错误
b = from y in da.Errors
选择
y. ER_Error_ID;
var
c = 来自 z in da.错误
c=from z in da.Errors
选择
z. ER_Error_Date;
var
fg = 来自 j in da.批次
fg=from j in da.Batches
其中
j. BT_Batch_End!= null
j.BT_Batch_End!=null
j;
var
n = 来自 g in da.ErrorTypes
n=from g in da.ErrorTypes
选择
g. ET_Error_Description;
数据表
dt = 新 DataTable ();
dt = new DataTable();
IEnumerable
IEnumerable
< DataRow > 查询=( 来自 x in da.Controls.AsEnumerable()
<DataRow> query = (from x in da.Controls.AsEnumerable()
选择
为
dt = query.CopyToDataTable<
dt = query.CopyToDataTable<
DataRow >();
DataRow>();
IEnumerable < DataRow > ;; 新 {x.CT_GUID_Type})
IEnumerable<DataRow>; new {x.CT_GUID_Type})
{
}
但是我想填充数据,要么将所有数据放入一个变量中,要么将所有变量放入一个数据表中.但是我不知道该步骤.我想将三个表的数据填充到DATATABLE中
But i want to fill the data either putting all the data in one variable or putting all the variable in one data table..But i don't know the step..I want to fill the data of three table into DATATABLE.
请帮助我.
我要使用此引用将数据从数据表写入csv.
For writting the data from data table to csv i am using this reference..
如果我错了,请帮助我,请指导我获得正确的输出.
Help me if i am wrong and please guide me to get the correct output..
http://www.dotnetspider.com/resources/21179-Convert-datatable -CSV-format.aspx
谢谢.
选择
公共
推荐答案
如果使用 SqlDataAdapter 检索了您的三个数据表, 您可以轻松地加入表格.
If your Three data tables are retrieved using SqlDataAdapter, you can join the tables easily.
SqlDataAdapter da =新的SqlDataAdapter(查询以检索 1st 数据表" ,, con);
SqlDataAdapter da= new SqlDataAdapter("query to retrieve 1st datatable",con);
DataSet ds = new DataSet();
DataSet ds= new DataSet();
da.Fill(ds," TableName ");
da.Fill(ds,"TableName");
da =新的SqlDataAdapter(要检索第二个数据表的查询",con);
da= new SqlDataAdapter("query to retrieve 2nd datatable",con);
da.Fill(ds," TableName ");
da.Fill(ds,"TableName");
da =新的SqlDataAdapter(要检索第3 个数据表的查询",con);
da= new SqlDataAdapter("query to retrieve 3rd datatable",con);
da.Fill(ds," TableName ");
da.Fill(ds,"TableName");
使用ds.Tables ["TableName"] 时,您将获得一个数据表,其中包含您在上面执行过的所有3个查询的数据.
When you use ds.Tables["TableName"] you will get a datatable which has data of all the 3queries you have executed above.
注意: TableName 应始终保持一致
希望这会有所帮助.
这篇关于从三个变量填充数据表,或将三个表的数据放入一个变量,然后生成数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!