一样的啦。
你直接把表与表之间的左联,右联,内联接写成一个SQL语句,或先写从一个视图再查询出来成一个DATASET传进去就可以了。然后你设计报表也照样把几个有关联的表拉过去,设一下是用哪个字段连接,进行相应的设计就可以了。
下面的例子供参考。protected void Page_Load(object sender, EventArgs e)
{
//连接字符在WEB.CONFIG获取
string connStr = ConfigurationSettings.AppSettings["lj"].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);
//强制连接数据库,在WEB.CONFIG获取
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>");
} }
你直接把表与表之间的左联,右联,内联接写成一个SQL语句,或先写从一个视图再查询出来成一个DATASET传进去就可以了。然后你设计报表也照样把几个有关联的表拉过去,设一下是用哪个字段连接,进行相应的设计就可以了。
下面的例子供参考。protected void Page_Load(object sender, EventArgs e)
{
//连接字符在WEB.CONFIG获取
string connStr = ConfigurationSettings.AppSettings["lj"].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);
//强制连接数据库,在WEB.CONFIG获取
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>");
} }
解决方案 »
- 动态的treeview树型控件,增删改
- 怎样将颜色字符串转换为整形?
- webconfig 中没有sessionState
- ASP.NET2.0 中 textbox Enabled 属性 随着RadioButton 的Checked 改变
- 怎么对datalist 里面的控件进行动态的修改
- 求助,datagrid打印
- 操作日志??? 说的都有分
- 请教IIS+ASP.Net多线程出错,麻烦各位大哥大姐们路过看看,Thx
- 急:怎么样才能查看asp.net中.dll文件的源代码啊?用什么工具啊?
- DataGrid简单问题
- .net2.0强名称发布网站web引用预编译出错问题
- API函數在IIS上失效問題
SqlDataAdapter MyAdapter = new SqlDataAdapter(sql,MyConn); MyAdapter.Fill(ds,"App_Prject"); oCR.SetDataSource(ds); 这是一个表的代码,多表的时候这句代码MyAdapter.Fill(ds,""); 这里引号里面填什么呢。
string sql="select a.*,b.字段 from App_Prject a,App_Prject1 b where a.id=b.id";
SqlDataAdapter MyAdapter = new SqlDataAdapter(sql,MyConn);
MyAdapter.Fill(ds,"App_Prject");
oCR.SetDataSource(ds);
然后你的画报表的时候就是把两个表都拉下去设计啦。把两个表所需要的字段放进去就好了。一样的道理