我試圖在我的c#窗體項目中顯示datagridview
中的數據。我不斷收到此錯誤填充:SelectCommand.Connection屬性尚未初始化錯誤
「填寫:SelectCommand.Connection屬性尚未初始化」
有什麼我做錯了這裏:
private void Form1_Load(object sender, EventArgs e)
{
try
{
SqlCommand db = new SqlCommand("select * from Tbls");
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = db;
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bsource = new BindingSource();
bsource.DataSource = dbdataset;
dataGridView1.DataSource = bsource;
sda.Update(dbdataset);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
看來,哈比卜,阿奎那和我都給你非常類似的解決方案。他們工作? –