C#水晶报表数据来源 问题~! 谢谢大家了!
在C#中水晶报表 可以有3种数据源可以选择, 最后一个是对象 可是我不知道怎么操作! 所以麻烦大家给我个小的示例源码! 谢谢了~~
------解决方案--------------------string connStr =ConfigurationSettings.AppSettings[ "ConnString1 "].ToString();
SqlDataSource datasource = new SqlDataSource(connStr, SQL语句);
ReportDocument doc = new ReportDocument();
TableLogOnInfo logininfo = new TableLogOnInfo();
string path;
path = Server.MapPath( "report1.rpt ");
doc.Load(path);
string a, b, c, d;
a = System.Configuration.ConfigurationManager.AppSettings[0];
b = System.Configuration.ConfigurationManager.AppSettings[1];
c = System.Configuration.ConfigurationManager.AppSettings[2];
d = System.Configuration.ConfigurationManager.AppSettings[3];
logininfo.ConnectionInfo.ServerName = a;
logininfo.ConnectionInfo.DatabaseName = b;
logininfo.ConnectionInfo.UserID = c;
logininfo.ConnectionInfo.Password = d;
try
{
doc.Database.Tables[0].ApplyLogOnInfo(logininfo);
doc.Database.Tables[0].SetDataSource(datasource.Select(DataSourceSelectArguments.Empty));
CrystalReportViewer1.ReportSource = doc;
}
catch
{
Response.Write( " <script> alert( '输出报表失败,请检查输入信息或网络! '); </script> ");
}