首页上一页 1 下一页尾页 1 条记录 1/1页
C#程序开发范例宝典中的数据库技术里的9.5数据录入问题
发表在C#图书答疑
2008-11-30
是否精华
是
否
版块置顶:
是
否
我是刚学编程的,买你们的那本C#程序开发范例宝典大多数是SQL版的。。
C#程序开发范例宝典中的数据库技术里的9.5数据录入能不能发个ACCESS版的,或帮我解决一下。在这里先谢谢啦!!
我的邮箱:sitra@21cn.com QQ:372705480
其实主要是连接数据库的那部分。这是我参考的但还是不知哪里出问题拉。。(
private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private BindingManagerBase MyBind;
private System.Data.OleDb.OleDbCommand oleDbCommand1;
private void Form1_Load(object sender, EventArgs e)
{
string strconn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\mydb.mdb";
System.Data.OleDb.OleDbConnection oleDbConnection1 = new OleDbConnection(strconn);
System.Data.OleDb.OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("select * from 客户", oleDbConnection1);
try
{
this.oleDbDataAdapter1.Fill(this.dataSet1,"客户");
this.textBox1.DataBindings.Add("Text",this.dataSet1,"客户.id");
this.textBox2.DataBindings.Add("Text",this.dataSet1,"客户.用户");
this.textBox3.DataBindings.Add("Text",this.dataSet1,"客户.密码");
this.MyBind=this.BindingContext[this.dataSet1,"客户"];
}
catch(Exception Err)
{
MessageBox.Show("打开数据库表错误:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string strconn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath+ "\\mydb.mdb";
System.Data.OleDb.OleDbConnection oleDbConnection1 = new OleDbConnection(strconn);
System.Data.OleDb.OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("select * from 客户", oleDbConnection1);
string StrSQL = "INSERT INTO 客户(id,用户,密码)VALUES('";
StrSQL += this.textBox1.Text + "','";
StrSQL += this.textBox2.Text + "','";
StrSQL += this.textBox3.Text + "')";
this.oleDbCommand1.CommandText = StrSQL;
this.oleDbCommand1.Connection = this.oleDbConnection1;
//打开数据库连接
this.oleDbConnection1.Open();
//执行SQL命令
this.oleDbCommand1.ExecuteNonQuery();
//关闭连接
this.oleDbConnection1.Close();
//更新数据集
this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].BeginEdit();
this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].EndEdit();
this.dataSet1.AcceptChanges();
//MessageBox.Show("增加数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch (Exception Err)
{
MessageBox.Show("增加数据集记录操作失败:" + Err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
希望大家来看看,,帮我解决一下。。。。。。5555555555
C#程序开发范例宝典中的数据库技术里的9.5数据录入能不能发个ACCESS版的,或帮我解决一下。在这里先谢谢啦!!
我的邮箱:sitra@21cn.com QQ:372705480
其实主要是连接数据库的那部分。这是我参考的但还是不知哪里出问题拉。。(
private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
private System.Data.OleDb.OleDbConnection oleDbConnection1;
private BindingManagerBase MyBind;
private System.Data.OleDb.OleDbCommand oleDbCommand1;
private void Form1_Load(object sender, EventArgs e)
{
string strconn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\mydb.mdb";
System.Data.OleDb.OleDbConnection oleDbConnection1 = new OleDbConnection(strconn);
System.Data.OleDb.OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("select * from 客户", oleDbConnection1);
try
{
this.oleDbDataAdapter1.Fill(this.dataSet1,"客户");
this.textBox1.DataBindings.Add("Text",this.dataSet1,"客户.id");
this.textBox2.DataBindings.Add("Text",this.dataSet1,"客户.用户");
this.textBox3.DataBindings.Add("Text",this.dataSet1,"客户.密码");
this.MyBind=this.BindingContext[this.dataSet1,"客户"];
}
catch(Exception Err)
{
MessageBox.Show("打开数据库表错误:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string strconn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath+ "\\mydb.mdb";
System.Data.OleDb.OleDbConnection oleDbConnection1 = new OleDbConnection(strconn);
System.Data.OleDb.OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("select * from 客户", oleDbConnection1);
string StrSQL = "INSERT INTO 客户(id,用户,密码)VALUES('";
StrSQL += this.textBox1.Text + "','";
StrSQL += this.textBox2.Text + "','";
StrSQL += this.textBox3.Text + "')";
this.oleDbCommand1.CommandText = StrSQL;
this.oleDbCommand1.Connection = this.oleDbConnection1;
//打开数据库连接
this.oleDbConnection1.Open();
//执行SQL命令
this.oleDbCommand1.ExecuteNonQuery();
//关闭连接
this.oleDbConnection1.Close();
//更新数据集
this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].BeginEdit();
this.dataSet1.Tables["客户"].Rows[this.MyBind.Position].EndEdit();
this.dataSet1.AcceptChanges();
//MessageBox.Show("增加数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch (Exception Err)
{
MessageBox.Show("增加数据集记录操作失败:" + Err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
希望大家来看看,,帮我解决一下。。。。。。5555555555