【发布时间】:2016-04-16 06:55:49
【问题描述】:
我在我的 C# 窗口窗体中使用 3 层架构。我想做的是,如果数据存在,则隐藏按钮。这是我的代码。
类文件
public bool checkIfExists(Variables variables) { // BelPar
SqlCommand check = new SqlCommand();
check.Connection = dbcon.getcon();
check.CommandType = CommandType.Text;
check.CommandText = "SELECT * FROM tbl";
SqlDataReader drCheck = check.ExecuteReader();
if(drCheck.HasRows == true)
{
drCheck.Read();
if (... && .. ||) // conditions where variables are being fetch
{
return false;
}
}
drCheck.Close();
return true;
}
窗体
btn_save.Visible = !balpayrolldetails.checkIfExists(); // This is where I get the "No overload for method 'checkIfExists' takes 0 arguments.
有什么帮助吗?请在下方留言或回答。谢谢
【问题讨论】:
-
错误已经说明了。您需要函数 checkIfExists 的参数(变量类型)
-
当然,checkIfExists 需要一个参数。查看您的方法定义 public bool checkIfExists(Variables variables) 您没有传递 Variables 参数
-
为了简单支持无参数调用,可以将签名改为
checkIfExists(Variables variables=null) -
顺便说一下和3-tier没有关系,最好把它从title中去掉,去掉tag:)