如何在C#中将'System.Data.DataTable'设置为'WindowsFormsApplication1.DataSet1'? [英] how to set 'System.Data.DataTable' to 'WindowsFormsApplication1.DataSet1' in C#?
本文介绍了如何在C#中将'System.Data.DataTable'设置为'WindowsFormsApplication1.DataSet1'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我将System.Data.DataTable设置为DataSet1.Tables时出现错误,错误是无法将类型''System.Data.DataTable''转换为''WindowsFormsApplication1.DataSet1''..
我想用我的自定义字段创建一个没有数据库字段的Crystal报表(不想要Data.DataSet)...
我的代码是 - :
I get en error when i set System.Data.DataTable to DataSet1.Tables the error is "Cannot convert type ''System.Data.DataTable'' to ''WindowsFormsApplication1.DataSet1''"..
I want to create a Crystal report without database fields with my custom fields(Don''t want Data.DataSet)...
My Code is -:
DataSet1 ds1 = new DataSet1();
OleDbConnection con=new OleDbConnection("Provider=Microsoft.jet.oledb.4.0; data source="+Application.StartupPath+@"\DataInfo1.mdb");
con.Open();
OleDbDataAdapter da=new OleDbDataAdapter(@"SELECT ct.custID, c.custName, c.custAdd, ct.custTranDate, ct.custTranType, ct.custPaidAmt, ct.custDueAmt, c.custArea FROM custTransaction AS ct LEFT JOIN custDetails AS c ON ct.custID = c.custID WHERE ct.custID='CUST-000002' and ct.custTranDate BETWEEN #2/28/13# AND #3/1/13#;",con);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
da.Fill(dt);
ds1 = dt; //Error is here
// MessageBox.Show(ds1.Tables[0].Rows.Count.ToString());
CrystalReport2 cr = new CrystalReport2();
cr.SetDataSource(ds1);
this.crystalReportViewer1.ReportSource =cr;
this.crystalReportViewer1.Show();
谢谢提前....
Thanks in Advance....
推荐答案
一个DataTable
和一个DataSet
是不同的类型,你不能使用你编码的表达式。转到MSDN并阅读每个类的文档。
ADataTable
and aDataSet
are different types, you cannot use an expression such as you have coded. Go to MSDN and read the documentation for each class.
这篇关于如何在C#中将'System.Data.DataTable'设置为'WindowsFormsApplication1.DataSet1'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文