关于一个C#的问题
我用的时access2007数据库,为什么我做的操作不能更新到数据库中去,求指点。
代码:
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 System.Data.OleDb;
namespace 学生信息档案管理系统
{
public partial class ScoreUpdate : Form
{
OleDbConnection connection = new OleDbConnection(help.connstr);
OleDbCommand cmd;
OleDbDataAdapter da;
OleDbCommandBuilder cb;
DataSet ds = new DataSet();
BindingSource bind = new BindingSource();
public ScoreUpdate()
{
InitializeComponent();
}
private void ScoreUpdate_Load(object sender, EventArgs e)
{
bind.DataSource = Getdt();
this.bindingNavigator1.BindingSource = bind;
this.dataGridView1.DataSource = bind;
}
public DataTable Getdt()
{
cmd = new OleDbCommand("select U_Account,U_Pass from User_Login", connection);
da = new OleDbDataAdapter(cmd);
da.Fill(ds);
return ds.Tables[0];
}
private void button1_Click(object sender, EventArgs e)
{
cmd = new OleDbCommand("select U_Account,U_Pass from User_Login", connection);
da = new OleDbDataAdapter(cmd);
cb = new OleDbCommandBuilder(da);
da.InsertCommand = cb.GetInsertCommand();
da.DeleteCommand = cb.GetDeleteCommand();
da.UpdateCommand = cb.GetUpdateCommand();
bind.EndEdit();//提交未更改,应用于数据
da.Update(ds);
MessageBox.Show("操作成功");
ds.Clear();
bind.DataSource = Getdt();
this.bindingNavigator1.BindingSource = bind;
bind.MoveLast();//绑定到最后一条数据
}
}
}