我的完整代码按钮点击事件 我保存到sample.xml的方案...我使用这个模式进行水晶报告,然后按照你的建议绑定数据
protected void Button1_Click1(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("BLOCK NO ", typeof(string));
dt.Columns.Add("DATE ", typeof(string));
dt.Columns.Add("SESSION ", typeof(string));
dt.Columns.Add("USN ", typeof(string));
dt.Columns.Add("SUBJECT CODE ", typeof(string));
dt.Columns.Add("SEAT/BENCH ", typeof(string));
dt.Columns.Add("SUPERVISOR ", typeof(string));
SqlDataAdapter adptdate = new SqlDataAdapter("select * from blocks_allocation order by date,session,block,bench", con);
DataSet DSall = new DataSet();
adptdate.Fill(DSall);
for (int j = 0; j < DSall.Tables[0].Rows.Count; j++)
{
DataRow DR = DSall.Tables[0].Rows[j];
dt.Rows.Add(DR.ItemArray.GetValue(0).ToString(), DR.ItemArray.GetValue(3).ToString(), DR.ItemArray.GetValue(4).ToString(), DR.ItemArray.GetValue(2).ToString(), DR.ItemArray.GetValue(5).ToString(), DR.ItemArray.GetValue(6).ToString(), DR.ItemArray.GetValue(1).ToString());
}
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.WriteXmlSchema("F:\\pramodblde\\Bin\\Sample.xml");
GridView1.DataSource = dt;
GridView1.DataBind();
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(Server.MapPath("blockreport.rpt"));//rpt file path
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
}