1

我只是想将编辑后的结果更新到数据库中,即在 datagridView 中编辑,因此用户不必看到任何弹出窗口或其他任何东西来编辑值,

我有这个代码,但它不工作:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using System.Data.OleDb;

namespace e_Examiner {
    public partial class Form1 : RibbonForm {
        Library lib = new Library();
        OleDbDataAdapter adapter;
        DataSet table;

        public Form1() {
            InitializeComponent();
            InitSkinGallery();
            InitGrid();
        }

        void InitSkinGallery() {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }

        void InitGrid() {
            lib.connectionOpen();
            OleDbCommand commnad = new OleDbCommand("SELECT * FROM teachers",         
               lib.dbConnection);
            table = new DataSet();
            adapter = new OleDbDataAdapter(commnad);
            OleDbCommandBuilder bulder = new OleDbCommandBuilder(adapter);
            adapter.Fill(table, "teachers");
            gridControl.DataSource = table.Tables["teachers"];
            lib.connectionClose();
        }

        private void layoutView1_CellValueChanged_1(object sender,          
            DevExpress.XtraGrid.Views.Base.
            CellValueChangedEventArgs e) {

            lib.connectionOpen();
            OleDbCommandBuilder bulder = new OleDbCommandBuilder(adapter);
            DataTable dt = table.Tables["teachers"];
            adapter.Update(dt);
            lib.connectionClose();
        }
    }
}
4

0 回答 0