日期:2014-05-20 浏览次数:21052 次
using Microsoft.Reporting.WinForms;
//取数据
searchstring = "select * from ShenBao";
conn.Fill(searchstring, "ShenBao");
int i = conn.ds.Tables["ShenBao"].Rows.Count;//断点可看到这个i=10000多,取来的数据没问题
//绑定数据,这四行都执行了
ReportDataSource rds = new ReportDataSource("DataSet1", conn.ds.Tables["ShenBao"]);
reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.LocalReport.Refresh();
/// <summary>
/// 建立DataSet对象,用记录填充或构架(如果必要)DataSet对象,DataSet即是数据在内存的缓存
/// </summary>
/// <param name="str_Sql">打开表Sql语句</param>
/// <param name="TableName">重载,可以接收表名</param>
public string Fill(string str_Sql, string TableName)
{
Open();
myAdapter = new System.Data.OleDb.OleDbDataAdapter(str_Sql, myConnection);
myAdapter.TableMappings.Add("Table", TableName);
//这个地方需要设置前面的sourcetable和datasettable吗?????????
水晶报表里,这里我这样设置没错啊!!!!!!!
ds = new DataSet();
try
{
myAdapter.Fill(ds, TableName);
}
catch (SqlException e)
{
string errorMessage = e.Message;
return errorMessage;
}
finally
{
myConnection.Dispose();
}
return "OK";
}