标签:rdl btn .com trim forms 建立 namespace soft partial
看看代码吧。现在我用Linq已经上瘾,对SQL语言已经几乎不用了,可惜的是rdlc不支持linq,要采用sql语言生成datatable,用datatable绑定rdlc,这里,应用了一个技巧,解决了这个问题。
还是那句话:看代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
using System.Configuration;//调用配置
namespace aspnet_nczx_xsxk
{
public partial class yj_cs_bb : System.Web.UI.Page
{
private nczx_xsxkEntities sjklj = new nczx_xsxkEntities();//数据库连接
private webncxk_class gj = new webncxk_class();//调用类中有关的函数
protected void Page_Load(object sender, EventArgs e)
{
try
{
//防止恶意登录
admin_user dq_gly = Session["stjBEF985E"] as admin_user;
if (dq_gly == null)
{
this.Response.Redirect("~/Login.aspx");
return;
}
}
catch
{
this.Response.Redirect("~/Login.aspx");
// this.btn_xx_cx.Text = err.Message;
}
if(!IsPostBack)
{
// //用linq生成的数据填充自己定义的dataset
// this.Response.Redirect("~/yj_cs_bb.aspx?cs=" + cs);
/*
string connstring = ConfigurationManager.ConnectionStrings["qsxkConnectionString"].ConnectionString;
// string connstring = "Data Source=.\\SQL2008R2;Initial Catalog=qsxk;Integrated Security=True";
SqlConnection conn = new SqlConnection(connstring);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Xs_xk";
conn.Open();
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
try
{
SqlDataAdapter ada1 = new SqlDataAdapter(cmd);
ada1.Fill(dt);
}
finally
{
conn.Close();
cmd.Dispose();
conn.Dispose();
}
*/
try
{
DataTable dt = new DataTable();//建立数据表结构
dt.Columns.Add("Kcmc", typeof(string));
dt.Columns.Add("Jsxm", typeof(string));
dt.Columns.Add("Sknd", typeof(string));
dt.Columns.Add("Xq", typeof(string));
dt.Columns.Add("Xm", typeof(string));
dt.Columns.Add("Xz", typeof(string));
dt.Columns.Add("Bj", typeof(string));
dt.Columns.Add("sjdd", typeof(string));
//分离查询条件
// string cs = sknd + "|" + xq + "|" + nj+"|"+dq_gly.dwid.ToString();//还要加:学校id,和“管理员”或教师姓名,如果是教师姓名,就转向教师查看选修课程的数据页面
string[] cxtj = this.Request.QueryString["cs"].ToString().Split(‘|‘);
string sknd = cxtj[0];
string xq = cxtj[1];
string nj = cxtj[2];
int dwid = int.Parse(cxtj[3].Trim());
var cx_db_xk = from aa in sjklj.Xs_xk
where aa.Sknd == sknd && aa.Xq == xq && aa.Xz == nj && aa.dwid == dwid
select aa;
foreach(var kk in cx_db_xk)
{
DataRow dr = dt.NewRow();
dr["Kcmc"] = kk.Kcmc;
dr["Jsxm"] = kk.Jsxm;
dr["Sknd"] = kk.Sknd;
dr["Xq"] = kk.Xq;
dr["Xm"] = kk.Xm;
dr["Xz"] = kk.Xz;
dr["Bj"] = kk.Bj;
dr["sjdd"] = kk.sjdd;
dt.Rows.Add(dr);
}
ReportDataSource rds = new ReportDataSource("DataSet1", dt);
this.ReportViewer1.LocalReport.DataSources.Clear();
this.ReportViewer1.LocalReport.DataSources.Add(rds);
//为报表浏览器指定报表文件
this.ReportViewer1.LocalReport.ReportEmbeddedResource = "aspnet_nczx_xsxk.Report1.rdlc"; //指定数据集,数据集名称后为表,不是DataSet类型的数据集
}
catch
{
}
}
}
}
}
标签:rdl btn .com trim forms 建立 namespace soft partial
原文地址:http://www.cnblogs.com/zrprj/p/7739682.html