关于在dataGridView中更新数据的问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 14:05:33
我是用本地的access数据库:
namespace WindowsApplication2
{
public partial class Form1 : Form
{
private DataTable DT = new DataTable();
private OleDbDataAdapter odb = new OleDbDataAdapter();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string strCon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\a\db1.mdb";
OleDbConnection MyCon = new OleDbConnection(strCon);
MyCon.Open();
OleDbCommand scd = new OleDbCommand("select * from [table]", MyCon);
odb.SelectCommand = scd;
odb.Fill(DT);
dataGridView1.DataSource = DT;
}
private void button2_Click(object sender, EventArgs e)
{
try
{
OleDbCommandB

这样是可以的啊 !我也是这样写的都好好的没问题的!不知道你说的那里出问题了。肯能是这样的,我是在用一个bindingNavgint控件在这个上面添加更新按钮的。你试试在这个上边加一个toolStripButton按钮,双击把上面你的Button的代码写进去。另外在把bindingNavgint控件和你的表绑定。
代码就写在那个dataGridView1.DataSource=Dt;下面。
代码:BindingSource bind=new BindingSource();
bind.DataSource=dataGridVeiw1.DataSource;
bindingNavgint1.BindingSource=bind;
这样就OK了你试试。

但是在dataGridView中更改数据后,单击按钮时,会报“system.data.oledb.oledbexception update 声明结构错误”。

没声明更新 单击事件 吧

数据库的问题...检查下代码...或者数据库连接...