关于一个C#的问题

Mcoolpen 2011-11-04 08:28:37
我用的时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();//绑定到最后一条数据
}
}
}
...全文
57 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mcoolpen 2011-11-06
  • 打赏
  • 举报
回复
解决了,是我的数据库文件放的位置有错,谢谢各位热情的解答
山东蓝鸟贵薪 2011-11-04
  • 打赏
  • 举报
回复
奇怪,我也没有找到“更新”语句呀???
黄亮 2011-11-04
  • 打赏
  • 举报
回复
da应该用同一个试试。别new2个
PaulyJiang 2011-11-04
  • 打赏
  • 举报
回复
何来更新?没看到啊
幸福的小木鱼 2011-11-04
  • 打赏
  • 举报
回复
绑定的时候加上this.DataBind()
山东蓝鸟贵薪 2011-11-04
  • 打赏
  • 举报
回复
跟踪一下,试试吧、
可能参数就没有传递呀

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧