我试图通过按照
中给出的步骤查询表中的记录来显示报告http://www.codeproject.com/Articles/166291/Generate-a-report-using-Crystal-Reports-in-Visual
我收到错误的行
ds.Tables [0] .Merge(DT);
因为不包含'Tables'的定义而且没有扩展方法'tables'接受类型的第一个参数可以找到(你是否缺少using指令或汇编引用?)
在下面的代码中。请帮忙。
Emp是数据集
中的xsd文件名(Emp.xsd)protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
Emp ds = new Emp(); // Emp is the xsd file name (Emp.xsd)
DataTable dt = new DataTable();
// Just set the name of data table
dt.TableName = "EmployeeStats";
dt = AB.GetEEmpStats((int)Session["EmpID"]); //Call function to get the employee statistics
ds.Tables[0].Merge(dt); <<<<<<<<<<<<<<<<<<< Error at this line
// .rpt file path
rptEmpStat.Load(Server.MapPath("EmpStats.rpt"));
//dataset to the report viewer.
rptDoc.SetDataSource(ds);
Emp.ReportSource = rptDoc;
Emp.RefreshReport();
}
GetEEmpStats的代码位于
之下 public DataTable GetEEmpStats(int ID)
{
//Connection string
//string sqlCon = <***************>;
SqlConnection Con = new SqlConnection(sqlCon);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
SqlDataAdapter adapter;
try
{
Con.Open();
//Stored procedure
cmd.CommandText = "sp_getEmpDetails";
cmd.CommandType = CommandType.StoredProcedure;
// input parameter
SqlParameter parameter1 = new SqlParameter();
parameter1.ParameterName = "@ID";
parameter1.SqlDbType = SqlDbType.Int;
parameter1.Direction = ParameterDirection.Input;
parameter1.Value = ID;
// Add the parameter to the Parameters collection.
cmd.Parameters.Add(parameter1);
cmd.Connection = Con;
ds = new DataSet();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "EmpDet");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (Con.State != ConnectionState.Closed)
Con.Close();
}
return ds.Tables[0];
}