日期:2014-05-18  浏览次数:21057 次

[C#]急救!直接在DataGridView编辑更新,怎么让它同步更新数据库(Access)
DataGridView我已用封装方法绑定好了,
然后我直接在DataGridView上进行编辑,当我点保存后怎么让它直接更新数据库里面的数据(ACcess数据库)

------解决方案--------------------

ds.update

------解决方案--------------------
冒泡帮顶接分

看你的datagridview用什么数据绑定形式了

usersBindingSource.EndEdit();

usersTableAdapter.Update(accountDataDataSet.Users);
------解决方案--------------------
楼主参考下
C# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;


namespace WindowsApplication4
{
    public partial class Form1 : Form
    {
        OleDbDataAdapter da;
        DataTable dt;
        OleDbConnection cn;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            da.Update(dt);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Northwind.mdb");

            da = new OleDbDataAdapter("select * from orders", cn);

            OleDbCommandBuilder cb = new OleDbCommandBuilder(da);

            dt = new DataTable();

            da.Fill(dt);
            dataGridView1.DataSource = dt;


        }
    }
}