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); } }
//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]; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)