我的DAL文件是
public class dalEmployeeInformation
{
public string MyProperty_EmployeeID { get; set; }
public string MyProperty_EmpFirstName { get; set; }
public string MyProperty_EmpLastName { get; set; }
public string MyProperty_Exception { get; set; }
private DataSet dsEmployee = new DataSet();
public DataSet MyProperty_dsEmployee
{
get { return dsEmployee; }
set { dsEmployee = value; }
}
private DataTable dtEmployee = new DataTable();
public DataTable MyProperty_dtEmployee
{
get { return dtEmployee;}
set { dtEmployee = value; }
}
}
这就是我用它来保存
的方法 public void AddEmployee(dalEmployeeInformation obj)
{
try
{
cmd.CommandText = "addEmployee";
cmd.Parameters.AddWithValue("@EmpID", obj.MyProperty_EmployeeID);
cmd.Parameters.AddWithValue("@FirstName", obj.MyProperty_EmpFirstName);
cmd.Parameters.AddWithValue("@LastName", obj.MyProperty_EmpLastName);
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
catch (Exception ex)
{
obj.MyProperty_Exception = ex.Message;
}
}
这就是我用它来检索数据的方式。
public dalEmployeeInformation ViewSelectedEmployee(dalEmployeeInformation obj)
{
try
{
cmd.CommandText = "getSelectedEmployeeInfo";
cmd.Parameters.AddWithValue("@EmpID", obj.MyProperty_EmployeeID);
ada.Fill(obj.MyProperty_dsEmployee , "SelectedEmployee");
ada.Fill(obj.MyProperty_dtEmployee );
return obj;
}
catch (Exception ex)
{
obj.MyProperty_Exception = ex.Message;
return obj;
}
}
在form.cs
中 private void AddEmployee()
{
blEmployeeInformation bl = new blEmployeeInformation();
dalEmployeeInformation dal = new dalEmployeeInformation();
dal.MyProperty_Exception = "";
dal.MyProperty_EmployeeID = txtEmployeeID.Text;
dal.MyProperty_EmpFirstName = txtEmpFirstName.Text;
dal.MyProperty_EmpLastName = txtEmpLastName.Text;
bl.AddEmployee(dal);
if (dal.MyProperty_Exception == "")
{
MessageBox.Show("Employee Added Successfully");
}
else
{
MessageBox.Show("Employee not Added");
}
}
但是当我尝试调试它时会出现此错误信息
错误3类型或命名空间名称' dalEmployeeInformation'不能 找到(你错过了使用指令或汇编引用吗?)
错误2类型或命名空间名称' blEmployeeInformation'不能 找到(你错过了使用指令或汇编引用吗?)
答案 0 :(得分:0)
右键单击解决方案资源管理器中的“参考”文件夹,然后单击“添加参考”,然后参考BL和DAL文件夹(项目)。
然后在form.cs文件中添加两行
using BL;
using DAL;