标题:[求助]数据库运行没有问题但插入不了数据
只看楼主
sohaogo
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-18
 问题点数:0 回复次数:0 
[求助]数据库运行没有问题但插入不了数据

private OleDbDataAdapter ad;
private DataSet ds = new DataSet();

private OleDbCommandBuilder mybd;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

string strcon = "provider=microsoft.jet.oledb.4.0;data source=db1.mdb";
OleDbConnection connection= new OleDbConnection(strcon);
string st = "select * from s";
connection.Open();
OleDbDataAdapter ad = new OleDbDataAdapter(st,connection);
OleDbCommandBuilder odb = new OleDbCommandBuilder(ad);
DataSet ds = new DataSet();
ad.Fill(ds,"s");
System.Windows.Forms.BindingManagerBase mybin;
mybin=this.BindingContext[ds,"s"];
OleDbCommand mycommand = new OleDbCommand("insert into s values ('"+textBox1.Text+"','"+textBox2.Text+"')",connection);
mycommand.ExecuteNonQuery();
ds.Tables["s"].Rows[mybin.Position].BeginEdit();
ds.Tables["s"].Rows[mybin.Position].EndEdit();
ds.Tables["s"].AcceptChanges();
connection.Close();
dataGrid1.SetDataBinding(ds, "s");

搜索更多相关主题的帖子: 数据库 运行 
2006-06-07 16:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-70413-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.153659 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved