Shovan Saha

Shovan Saha

  • NA
  • 321
  • 92.6k

Select from data grid view

May 5 2017 5:03 AM
This is in visual studio 2015, C# and MS Access database. I want to select from datagrid view not from database. How? Please code or example. 
 
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
con = new OleDbConnection(conString);
string sql = "SELECT * FROM LalData WHERE SuspenceAccount like '" + comboBox1.Text + "%'";
con.Open();
adapter = new OleDbDataAdapter(sql, con);
dt = new DataTable();
adapter.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0];
btnSubmit.Enabled = false;
con.Close();
}
 

Answers (3)