简体   繁体   English

通过数据集foreach比较文本框文本C#

[英]foreach through dataset to compare textbox text C#

Im getting really stuck trying to iterate through a dataset to check if the company name entered into a textbox (TXTBXCustomerLookup) matches any of the entries in the dataset in column "CompanyName" when the button is pressed 我真的很难尝试遍历数据集,以检查按下按钮时输入到文本框(TXTBXCustomerLookup)中的公司名称是否与“ CompanyName”列中的数据集中的任何条目相匹配

So far I have this: 到目前为止,我有这个:

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;
                        }
                    }
                }
            }
        }
    }

and it is coming up with the error "Cannot implicitly convert type 'String' to 'Bool" and "Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method" 并且出现错误“无法将类型'String'隐式转换为'Bool'和“无法将方法组'ToString'转换为非委托类型'string'。您是否打算调用该方法”

These errors are on the line below 这些错误在下面的行中

if (TXTBXCustomerLookup.Text = this.CompanyName.ToString())

I know it must be something simple I'm doing wrong but cannot think what and have spend over an hour trying to figure it out (using old trusty google) 我知道这一定是简单的事情,但我做错了,但无法思考,花了一个多小时试图弄清楚(使用旧的可信赖的Google)

if (TXTBXCustomerLookup.Text == this.CompanyName.ToString())

You need two = signs. 您需要两个=符号。 Otherwise your trying to assign the compannyname value to your TXTBXCustormerLookup textbox. 否则,您尝试将compannyname值分配给TXTBXCustormerLookup文本框。

if (TXTBXCustomerLookup.Text == this.CompanyName.ToString()){
    BTNUpdateCustomer.Enabled = true;
    BTNDeleteCustomer.Enabled = true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM