Hi Folks,
I am trying to search records in the database based on input value in Textbox (txtStudentName is the one) and want to populate the records into datagrid control On the form load, i am populating the datagrid with the full table. What actually i want is that as soon as i click search button, the datagrid should be filled with the search result and the full table should not come. I have written the below piece of logic for the same-->
try
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[1].Value.ToString().Equals(searchValue))
{
//row.Selected = true;
break;
}
}
}
Now my doubt is how should i populate the datagrid with this search results
private void Form1_Load(object sender, EventArgs e)
{
string connectionString = "Data Source=.;Initial Catalog=Student;Integrated Security=True";
string sql = "SELECT * FROM Student_Detail";
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
connection.Open();
DataSet ds = new DataSet();
dataadapter.Fill(ds, "Student_Detail");
connection.Close();
}
dataGridView1.DataSource = ds.Tables[0];
}
private void btnSearch_Click(object sender, EventArgs e)
{

Sreekanth ReddyRank #726 · 3.2K reputationPosted Nov 3, 2015, 12:47 AM EST
Sumit Dwivedi8 reputationPosted Nov 3, 2015, 1:44 AM EST
Sumit Dwivedi8 reputationPosted Nov 3, 2015, 4:57 AM EST
Arun Kumar41 reputationPosted Nov 8, 2015, 7:09 PM EST
Sreekanth ReddyRank #726 · 3.2K reputationPosted Nov 3, 2015, 2:48 AM EST