我想在DataGridView.here顯示我的DB表數據是我的代碼使用選擇查詢,顯示在數據網格視圖數據
private void button1_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("Data Source=SHIRWANIPC;" +
"Initial Catalog=TEST DATABASE;" + "Integrated Security=True");
myConnection.Open();
SqlCommand objcmd = new SqlCommand("SELECT * FROM Customer", myConnection);
SqlDataAdapter adp = new SqlDataAdapter(objcmd);
DataTable dt = new DataTable();
//adp.Fill(dt);
DataGridView.DataSource = adp.Fill(dt);
}
代碼現在沒有給予任何錯誤,但但它dosent顯示我的表格中的數據在我的網格?
我已經做到了這一點 數據表dt = new DataTable(); adp.Fill(dt); DataGridView DView = new DataGridView(); DView.DataSource = dt; DView.DataBind(); 它不識別DataBind(); – user3085866