我正在尝试按照以下给出的步骤从表中查询记录来显示报告
http://www.codeproject.com/Articles/166291/Generate-a-report-using-Crystal-Reports-in-Visual
我收到一条错误消息
ds.Tables[0].Merge(dt);
as 不包含“表”的定义,并且找不到接受第一个类型参数的扩展方法“表”(您是否缺少 using 指令或程序集引用?)
在下面的代码中。请帮忙。
Emp 是 Dataset 所在的 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];
}