Lets say I have a table named Table_T in the SQL database and it contains 6 columns (column1, column2, ..., column6).
The following code populates all columns from the database into dataGridView:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(
"Data Source=PCN-TOSH;Initial Catalog=mydb;Integrated Security=True");
cn.Open();
SqlCommand cm = new SqlCommand("SELECT *FROM Table_T");
cm.Connection = cn;
SqlDataAdapter da = new SqlDataAdapter(cm);
DataTable dt = new DataTable();
da.Fill(dt);
cn.Close();
dataGridView1.DataSource = dt;
}
But how can I only select column3 & column5 and populate them into dataGridview1?