添加到女士访问 [英] Adding to Ms Access

查看:75
本文介绍了添加到女士访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从数据库中检索数据,但是不能在其中添加数据.请帮我.这是我的代码:

I can retrieve data from the database but I can''t add data in it. Please help me. Here is my code:

string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\lala\\bin\\Debug\\GreenTech.mdb;User ID=Admin";
            OleDbConnection conn = new OleDbConnection(connectionString);
            conn.Open();
            OleDbCommand objCmd = new OleDbCommand("Insert into VisitorList(ID,Name,Design,Min) values (@Id,@name,@design,@min)",conn);
            objCmd.Parameters.Add("@Id", OleDbType.VarChar).Value = this.textBox4.Text;
            objCmd.Parameters.Add("@name", OleDbType.VarChar).Value = this.textBox1.Text;
            objCmd.Parameters.Add("@design", OleDbType.VarChar).Value = this.textBox2.Text;
            objCmd.Parameters.Add("@min", OleDbType.VarChar).Value = this.textBox3.Text;
conn.close();

推荐答案

您没有在任何地方执行命令.是不是问题?
You are not executing your command anywhere. Is that the problem?


否.当我触发按钮时执行的命令.其内部的mySave_button函数.香港专业教育学院想知道为什么我可以检索数据但不能添加它吗?


private void button1_Click(对象发送者,EventArgs e)
{
字符串connectionString ="Provider = Microsoft.Jet.OLEDB.4.0;数据源= C:\\ lala \\ bin \\ Debug \\ GreenTech.mdb;用户ID = Admin";
OleDbConnection conn =新的OleDbConnection(connectionString);
conn.Open();
OleDbCommand objCmd =新的OleDbCommand(插入VisitorList(ID,Name,Design,Min)值(@ Id,@ name,@ design,@ min)",conn);
objCmd.Parameters.Add("@ Id",OleDbType.VarChar).Value = this.textBox4.Text;
objCmd.Parameters.Add("@ name",OleDbType.VarChar).Value = this.textBox1.Text;
objCmd.Parameters.Add("@ design",OleDbType.VarChar).Value = this.textBox2.Text;
objCmd.Parameters.Add("@ min",OleDbType.VarChar).Value = this.textBox3.Text;
conn.close();

}
No.. the command executed when i trigger a button. its inside mySave_button function. ive wonder why i can retrieve the data but cant add it?


private void button1_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\lala\\bin\\Debug\\GreenTech.mdb;User ID=Admin";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand objCmd = new OleDbCommand("Insert into VisitorList(ID,Name,Design,Min) values (@Id,@name,@design,@min)",conn);
objCmd.Parameters.Add("@Id", OleDbType.VarChar).Value = this.textBox4.Text;
objCmd.Parameters.Add("@name", OleDbType.VarChar).Value = this.textBox1.Text;
objCmd.Parameters.Add("@design", OleDbType.VarChar).Value = this.textBox2.Text;
objCmd.Parameters.Add("@min", OleDbType.VarChar).Value = this.textBox3.Text;
conn.close();

}


我的意思是您没有在此事件的任何地方调用ExecuteNonQuery.因此,数据不会进入数据库.
I meant you are not calling ExecuteNonQuery anywhere in this event. Hence the data is not going to get into the database.


这篇关于添加到女士访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆