在一个窗体中,我点击button1,然后是像数据库中的一张数据表插入数据!下面的是我的代码
string source = "pcdb.mdb";
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + source;
string sql = "insert into [jswg] (完工日期,工号,姓名,工序编号,工序名称,工作时间,备注) values(@wgrq,@gh,@xm,@gxbm,@gxmc,@gzsj,@bz)";
OleDbConnection olecon = new OleDbConnection(conn);
olecon.Open();
OleDbCommand olecmd = new OleDbCommand(sql, olecon);
olecmd.Parameters.Add("@wgrq", OleDbType.DBDate, 50).Value = dateTimePicker1.Text;
olecmd.Parameters.Add("@gh", OleDbType.VarChar, 50).Value = this.textBox7.Text;
olecmd.Parameters.Add("@xm", OleDbType.VarChar, 50).Value = this.textBox1.Text;
olecmd.Parameters.Add("@gxbm", OleDbType.VarChar, 50).Value = this.textBox2.Text;
olecmd.Parameters.Add("@gxmc", OleDbType.VarChar, 50).Value = this.comboBox1.SelectedText.ToString();
olecmd.Parameters.Add("@gzsj", OleDbType.Integer, 50).Value = Convert.ToInt32(this.textBox3.Text);
olecmd.Parameters.Add("@bz", OleDbType.VarChar, 50).Value = this.textBox5.Text;
int i = Convert.ToInt32(olecmd.ExecuteNonQuery());
if (i > 0)
{
MessageBox.Show("插入成功! ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("发现异常!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
olecon.Close();
运行时我点击插入按钮后,弹出插入成功对话框,但是我的数据表中却没有数据,郁闷,哪位知道我哪里错了!
string source = "pcdb.mdb";
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + source;
string sql = "insert into [jswg] (完工日期,工号,姓名,工序编号,工序名称,工作时间,备注) values(@wgrq,@gh,@xm,@gxbm,@gxmc,@gzsj,@bz)";
OleDbConnection olecon = new OleDbConnection(conn);
olecon.Open();
OleDbCommand olecmd = new OleDbCommand(sql, olecon);
olecmd.Parameters.Add("@wgrq", OleDbType.DBDate, 50).Value = dateTimePicker1.Text;
olecmd.Parameters.Add("@gh", OleDbType.VarChar, 50).Value = this.textBox7.Text;
olecmd.Parameters.Add("@xm", OleDbType.VarChar, 50).Value = this.textBox1.Text;
olecmd.Parameters.Add("@gxbm", OleDbType.VarChar, 50).Value = this.textBox2.Text;
olecmd.Parameters.Add("@gxmc", OleDbType.VarChar, 50).Value = this.comboBox1.SelectedText.ToString();
olecmd.Parameters.Add("@gzsj", OleDbType.Integer, 50).Value = Convert.ToInt32(this.textBox3.Text);
olecmd.Parameters.Add("@bz", OleDbType.VarChar, 50).Value = this.textBox5.Text;
int i = Convert.ToInt32(olecmd.ExecuteNonQuery());
if (i > 0)
{
MessageBox.Show("插入成功! ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("发现异常!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
olecon.Close();
运行时我点击插入按钮后,弹出插入成功对话框,但是我的数据表中却没有数据,郁闷,哪位知道我哪里错了!
解决方案 »
- C#两个知识点:多线程与简单的socket
- PB代码转换成C#代码,求高手指点
- WinForm中的DataGrid模拟excel单元格单击和双击事件
- 事件订阅不上的问题
- 用DirectShow开发播放器如何实现全屏?
- 如何匹配指定ID的html内容?
- [求助]如何取COMBOX里的值!!
- 散分讨论:Socket.AcceptSocket()后陆续有客户端连接进来,我的想法是用一个列表Hashtable保存连接,当我想与某一个客户端通信时,可以从
- 音频的语音区是多少
- 求助!
- WinForm 子窗体在父窗体范围内移动,不能出父窗体???????急,最好有代码?
- 我想定时刷新一下数据集库,并在gridview中显示,可是b/s下没有定时器,怎么做啊,谢谢,附代码立即给分!
string strInsert = " INSERT INTO wit (speed,temperature,flow,flow_sgm,deg,pluse,pressure,bip,bip_sgm,time_now) VALUES ('" + textBox4.Text + "','" + textBox6.Text + "','" + textBox10.Text + "','" + textBox9.Text + "','" + numericUpDown10.Value.ToString() + "','" + numericUpDown5.Value.ToString() + "','" + P + "','" + textBox1.Text + "','" + textBox14.Text + "','" + label40.Text + "')";
OleDbCommand inst = new OleDbCommand(strInsert, myConn);
inst.ExecuteNonQuery();
就是把你的 string sql = "insert into [jswg] (完工日期,工号,姓名,工序编号,工序名称,工作时间,备注) values(@wgrq,@gh,@xm,@gxbm,@gxmc,@gzsj,@bz)"; values 后面直接带你要插入数据 ('" + dateTimePicker1.Text+ "','" + textBox7+ "'......)
以前的数据库被覆盖
所以看不见你单独执行debug里的 exe 会看到的