-1

hello friends i am making one window base application now i have struck somewhere thats why i need help from you experts. i want to get value form the row and match from the combobox.please find where i am wrong in this code. please make it crrect

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

     }
faiz
  • 1
  • Check this link - http://stackoverflow.com/questions/6688157/how-to-set-selected-value-from-combobox – hm27 Jun 01 '15 at 07:07
  • sir i did this but now i am getting this error this error "object reference not set to an instance of an object" – faiz Jun 01 '15 at 07:08
  • Sir i have changed . but now i am getting – faiz Jun 01 '15 at 07:09

3 Answers3

1

have you check the type casting or null condition check in dataset?. Please brief about it.

hm27
  • 111
  • 5
  • Sir Caseno type is int in database – faiz Jun 01 '15 at 07:11
  • have you set text member and value member appropriately? Check this link for binding - http://net-informations.com/q/faq/combovalue.html – hm27 Jun 01 '15 at 07:13
0

In Place of casedetails.ValueMember use this casedetails.SelectedValue

EDIT :

if (ds.Tables["addcaasedetails"].Rows[i]["caseno"].ToString() == casedetails.SelectedValue.ToString())
ThePravinDeshmukh
  • 1,823
  • 12
  • 21
0

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

farrukh aziz
  • 162
  • 1
  • 2
  • 9