我真的陷入了尝试遍历数据集以检查输入到文本框中的公司名称(TXTBXCustomerLookup)是否与列" CompanyName"中的数据集中的任何条目匹配的问题。按下按钮时
到目前为止,我有这个:
private void BTNLookupCustomer_Click(object sender, EventArgs e)
{
if ((TXTBXCustomerLookup.Text != "") && (TXTBXCustomerLookup.Text != " "))
{
foreach (DataTable table in ds.Tables)
{
foreach (DataRow row in table.Rows)
{
foreach (object item in row.ItemArray)
{
if (TXTBXCustomerLookup.Text = this.CompanyName.ToString())
{
BTNUpdateCustomer.Enabled = true;
BTNDeleteCustomer.Enabled = true;
}
}
}
}
}
}
它出现了错误"无法隐式转换类型' String'到了Bool"和"无法转换方法组' ToString'到非委托类型'字符串'。您打算调用方法"
这些错误在下面一行
if (TXTBXCustomerLookup.Text = this.CompanyName.ToString())
我知道这一定很简单我做错了但却想不出什么,并花了一个多小时试图解决它(使用旧的可信赖的谷歌)
答案 0 :(得分:1)
if (TXTBXCustomerLookup.Text == this.CompanyName.ToString())
答案 1 :(得分:0)
你需要两个=标志。否则,您尝试将compannyname值分配给TXTBXCustormerLookup文本框。
if (TXTBXCustomerLookup.Text == this.CompanyName.ToString()){
BTNUpdateCustomer.Enabled = true;
BTNDeleteCustomer.Enabled = true;
}