我有这段代码,用于从 DataGrid 更新数据库
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace datagrid
{
public partial class Form1 : Form
{
private MySqlConnection conn;
private DataTable data;
private MySqlDataAdapter da;
private MySqlCommandBuilder cb;
public Form1()
{
InitializeComponent();
}
private void btnshow_Click(object sender, EventArgs e)
{
string c = "server=localhost;database=std;uid=root;password=";
conn = new MySqlConnection(c);
conn.Open();
data = new DataTable();
da = new MySqlDataAdapter("SELECT * FROM general",conn);
cb = new MySqlCommandBuilder(da);
da.Fill(data);
dataGridView1.DataSource = data;
}
private void btnupdate_Click(object sender, EventArgs e)
{
DataTable changes = data.GetChanges();
da.Update(changes);
data.AcceptChanges();
}
}
}
现在,当我按下更新按钮时,它向我显示了这个异常:
{“对于不返回任何键列信息的 SelectCommand,不支持为 UpdateCommand 生成动态 SQL。”}
现在请告诉我我该怎么办?