我在C#WinForms应用程序中使用的是三层体系结构。当我编译应用程序时,在我的Presentation layer form1.cs 中出现以下错误
代码:
private void btnSave_Click(object sender, EventArgs e)
{
BLL.clsBLL obj = new BLL.clsBLL();
string firstname = txtClientFirstName.Text;
string lastname = txtClientLastName.Text;
string age = txtClientAge.Text;
int Res = 0;
try
{
Res = obj.Save_Client(Client_FirstName, Client_Lastname, Client_Age);
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
if(Res ==1)
{
MessageBox.Show("Data Saved");
}
else
{
MessageBox.Show("Data Not Saved");
}
}
错误:
"BLL.clsLL"不包含"Save_Client"的定义,并且没有扩展方法"Save_Client"接受类型为的第一个参数找不到"BLL.clsLL"(是否缺少using指令或装配参考?)
BLL层中Save_Client的代码如下:
代码:
public int Save_Client(string Client_FirstName, string Client_Lastname, string Client_Age)
{
Boolean bopassed = true;
bopassed = Check_Rules(Client_FirstName, Client_Lastname, Client_Age);
DAL.clsDAL obj = new DAL.clsDAL();
int Res = 0;
try
{
if (bopassed == true)
{
obj.Insert_Clients(Client_FirstName, Client_Lastname, Convert.ToInt32(Client_Age));
Res = 1;
}
else
{
Res = 0;
}
}
catch (SqlException)
{
throw;
}
return Res;
}
private Boolean Check_Rules(Client_FirstName, Client_Lastname, Client_Age)
{
Boolean bolres = true;
if(Client_FirstName=="")
{
bolres=false;
}
if(Client_Lastname=="")
{
bolres=false;
}
if(Client_Age=="")
{
bolres=false;
}
return bolres;
}
错误:
"需要标识符"
在方法私有布尔校验规则(Client_FirstName,Client_Lastname,Client_Age)
我搞不清出错的原因。
有人能告诉我问题出在哪里吗?
您忘记在Check_Rules
方法中说明参数的类型。您需要更改此行:
private Boolean Check_Rules(Client_FirstName, Client_Lastname, Client_Age)
到此:
private Boolean Check_Rules(string Client_FirstName, string Client_Lastname, string Client_Age)