Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello sir. i need one help. in my window application i am making a search command from the two comboboxes . i have attached both comboboxes from the data base but i am not able to show respective results on the datagridview my codes are blow please check and tell me where i am wrong


private void btnadd_Click(object sender, EventArgs e)
      {
          try
          {
           on = new SqlConnection("Data Source=.;Initial Catalog=Mydatabase;Integrated Security=True");
              con.Open();
              string str = "select caseno,courtname,casetype,status,nameofcounsil from addcaasedetails where casetype='CAW' and caseno=1200";

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

              for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
              {


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

                      if (ds.Tables[0].Rows[i]["casetype"].ToString() == casetype2.SelectedValue.ToString())
                      {
                          dataGridView1.DataSource = ds.Tables[0].Rows;

                      }
                  }
              }

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


      }
Posted
Comments
Bh@gyesh 23-Jun-15 2:53am    
Hi,
Here you need to take some datatable first to store the matching result and then that datatable you can bind to datagrid view.

1 solution

C#
//Try this loop counter, before that please check is that issues with your SQL or Assigning code behind while debugging 

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
   {
      //assign DVG
      dataGridView1.DataSource = ds.Tables[0];
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900