My DataTable has three columns fetched from a database, while I need to bind only two columns of it to a DataGridView. Can you please help me with
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("connection string");
SqlDataAdapter adp = new SqlDataAdapter("select Fieldname1,fieldname2 from Table Name", con);
DataSet ds = new DataSet();
ds.Clear();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
dataGridView1.DataSource = ds.Tables[0];
}
Definitely it will work.