【问题标题】:get the combobox values from the row of the table and match从表的行中获取组合框值并匹配
【发布时间】:2015-08-14 13:25:24
【问题描述】:

你好朋友,我正在制作一个基于窗口的应用程序 现在我已经到了某个地方,这就是为什么我需要你们专家的帮助。 我想从行中获取值并从组合框匹配。请在此代码中找到我错的地方。请改正

private void btnadd_Click(object sender, EventArgs e)
    {

        try
        {


            con = new SqlConnection("Data Source=.;Initial Catalog=DSIIDC2;Integrated Security=True");
            con.Open();
            string str = "select * from addcaasedetails";

            SqlDataAdapter da = new SqlDataAdapter(str, con);
            DataSet ds = new DataSet();
            da.Fill(ds);

            for (int i = 0; i < ds.Tables["addcaasedetails"].Rows.Count; i++)
            {
                if (ds.Tables["addcaasedetails"].Rows[i]["caseno"] == casedetails.ValueMember)
                {
                    dataGridView1.Visible = true;
                }
            }

            }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

     }

【问题讨论】:

  • 先生,我这样做了,但现在我收到此错误此错误“对象引用未设置为对象的实例”
  • 先生,我变了。但现在我得到了

标签: c# .net


【解决方案1】:

使用casedetails.SelectedValue代替casedetails.ValueMember

编辑:

if (ds.Tables["addcaasedetails"].Rows[i]["caseno"].ToString() == casedetails.SelectedValue.ToString())

【讨论】:

    【解决方案2】:

    您是否检查过数据集中的类型转换或空条件检查? 请简要介绍一下。

    【讨论】:

    【解决方案3】:

    if(ds.Tables != null) { for (int i = 0; i < ds.Tables["addcaasedetails"].Rows.Count; i++) { if (ds.Tables["addcaasedetails"].Rows[i]["caseno"] == casedetails.SelectedValue) { dataGridView1.Visible = true; } } }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多