在一个窗体中,我点击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();
运行时我点击插入按钮后,弹出插入成功对话框,但是我的数据表中却没有数据,郁闷,哪位知道我哪里错了!

解决方案 »

  1.   

    试一下这样插入
    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+ "'......)
      

  2.   

    这个问题以前回答过你是在调试运行时插入成功的是在debug目录里面的数据库,但是你在下次调试运行时时会把 项目 目录里的mdb 数据库文件重新复制到debug目录里面的
    以前的数据库被覆盖
    所以看不见你单独执行debug里的 exe 会看到的