无法从';System.Data.Datat';到';员工';
本文关键字:Datat 员工 Data System | 更新日期: 2023-09-27 18:20:17
我正试图按ID搜索员工记录。因此,首先我搜索数据库,然后运行另一个函数来获取图像,但我得到了这个错误:
错误33的最佳重载方法匹配"DocketViewer.GetDivDriverLicence(int,Employee)"有一些无效参数
错误34参数2:无法从转换"System.Data.Datat"到"Employee"
这里有搜索员工的代码:
DataSet ds = Lookups.Employee.GetEmployee(Company.Current.CompanyID, JobID);
int MainCount = 1;
foreach (DataTable table in ds.Tables)
{
foreach (DataRow dr in table.Rows)
{
ulPODS.Controls.Add(GetLi("<a href='"#DriverLicence-" + MainCount + "'">Driver Licence-" + ds.Tables[0].Rows[0]["ID"].ToString() + "</a>"));
tabsPOD.Controls.Add(GetDivDriverLicence(MainCount, ds)); //error here
MainCount++;
}
}
显示图像的功能:
protected HtmlGenericControl GetDivDriverLicence(int Count, Employee em)
{
DataTable dt = new DataTable();
dt.Columns.Add("Image");
dt.Columns.Add("ID");
dt.Columns.Add("Title");
DataRow desRow = dt.NewRow();
desRow["Image"] = em.DriverLicenseScanImage;
desRow["ID"] = em.ID;
desRow["Title"] = em.EmployeeNum;
dt.Rows.Add(desRow);
HtmlGenericControl div = new HtmlGenericControl("div");
div.ID = "Driver Licence-" + Count;
FormView fv = new FormView();
fv.ID = "FormViewDriverLicence-" + Count;
fv.ItemTemplate = FormView.ItemTemplate;
fv.ItemCommand += new FormViewCommandEventHandler(fv_ItemCommand);
fv.DataBound += (sender, em) => { fv_DataBound(sender, em, "driverlicence"); };
fv.DataSource = dt;
fv.DataBind();
div.Controls.Add(fv);
return div;
}
您的问题是因为您的GetDivDriverLicence(int Count, Employee e)
将Employee
作为其第二个参数,并且您正在向它传递DataSet
:
tabsPOD.Controls.Add(GetDivDriverLicence(MainCount, ds)); // <--- ds is a DataSet, not an Employee.
更大的问题是:您试图对GetDivDriverLicence(int Count, Employee e)
方法中的Employee
实例执行什么操作?这是你可以只使用数据集中的一个字段吗?您有从数据表中的一行构建Employee
实例的方法吗?
编辑:根据您的评论,以下是您可以添加到foreach
循环中的内容示例:
var emp = new Employee((int) dr["ID"]);
emp.Name = dr["Name"].ToString();
emp.Age = short dr["Age"];
tabsPOD.Controls.Add(GetDivDriverLicence(MainCount, emp));
一个想法是这样的,你必须编写GetEmployeeFromDataSet
函数来进行转换,尽管我怀疑这会编译:
DataSet ds = Lookups.Employee.GetEmployee(Company.Current.CompanyID, JobID);
int MainCount = 1;
foreach (DataTable table in ds.Tables)
{
foreach (DataRow dr in table.Rows)
{
ulPODS.Controls.Add(GetLi("<a href='"#DriverLicence-" + MainCount + "'">Driver Licence-" + ds.Tables[0].Rows[0]["ID"].ToString() + "</a>"));
Employee emp = GetEmployeeFromDataSet(ds);
tabsPOD.Controls.Add(GetDivDriverLicence(MainCount, emp));
MainCount++;
}
}
Employee GetEmployeeFromDataSet(DataSet ds) {
Employee emp = new Employee();
// convert the data from the ds into the newly made emp.
return emp;
}