很简单的,绑定CommandBuilder对象就行了。代码如下:
namespace CplusData
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static SQLiteConnection conn = new SQLiteConnection("Data Source=F:\\Project\\Data\\test;Version=3;");
SQLiteCommand cmd = new SQLiteCommand("select * from usertab", conn);
SQLiteDataAdapter sda = new SQLiteDataAdapter();
DataSet ds=new DataSet();
private void Form1_Load(object sender, EventArgs e)
{
conn.Open();
sda.SelectCommand = cmd;
sda.Fill(ds,"usertab");
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "usertab";
conn.Close();
}
private void button1_Click(object sender, System.EventArgs e)
{
SQLiteCommandBuilder scb = new SQLiteCommandBuilder(sda);
scb.GetUpdateCommand();
sda.Update(ds,"usertab");
}
}
}
20rmb帮你写个demo。在dgv里编辑实时提交。