无法将类型为"System.Data.DataTable"的对象强制转换为类型"System.Data.DataSet".
}privatevoidbtntuichu_Click(objectsender,EventArgse){}privatevoidbtnqueding_Click(obj...
}
private void btntuichu_Click(object sender, EventArgs e)
{
}
private void btnqueding_Click(object sender, EventArgs e)
{
//this sqDataAdapter1.Update(this .)
if (textBox2.Text != "")
{
string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\VS 练习文件\Access\Database1.accdb";
OleDbConnection con = new OleDbConnection(str);
DataSet dstemp = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter(" select*from 表1 where 字段1 = '" + textBox2.Text + "'", con);
adapter.Fill(dstemp);
dataGridView2.DataSource = dstemp.Tables[0];
}
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void btnxiu_Click(object sender, EventArgs e)
{
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.Update(((DataSet)dataGridView2.DataSource).Tables[0]);
} 展开
private void btntuichu_Click(object sender, EventArgs e)
{
}
private void btnqueding_Click(object sender, EventArgs e)
{
//this sqDataAdapter1.Update(this .)
if (textBox2.Text != "")
{
string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\VS 练习文件\Access\Database1.accdb";
OleDbConnection con = new OleDbConnection(str);
DataSet dstemp = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter(" select*from 表1 where 字段1 = '" + textBox2.Text + "'", con);
adapter.Fill(dstemp);
dataGridView2.DataSource = dstemp.Tables[0];
}
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void btnxiu_Click(object sender, EventArgs e)
{
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.Update(((DataSet)dataGridView2.DataSource).Tables[0]);
} 展开
展开全部
dataGridView2.DataSource = dstemp.Tables[0];//这一句中DataGridView2的DataSource是一个Table,
da.Update(((DataSet)dataGridView2.DataSource).Tables[0]);//这一句中又将DataGridView的DataSource显式转为DataSet,相当于(DataSet)DataTable,所以报错.
da.Update(((DataSet)dataGridView2.DataSource).Tables[0]);//这一句中又将DataGridView的DataSource显式转为DataSet,相当于(DataSet)DataTable,所以报错.
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询