| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 832 人关注过本帖
标题:每次对access数据库执行insert命令,都会清除以前输入的数据,何故?
只看楼主 加入收藏
weilight2008
Rank: 1
等 级:新手上路
帖 子:111
专家分:4
注 册:2005-10-5
结帖率:50%
收藏
 问题点数:0 回复次数:3 
每次对access数据库执行insert命令,都会清除以前输入的数据,何故?
情况是这样的,向access数据库写入数据的代码如下:
程序代码:
 OleDbConnection offier_connection = new OleDbConnection();
                offier_connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=officer.mdb";               
                offier_connection.Open();           
                OleDbCommand save_Command = offier_connection.CreateCommand();
                save_ = "INSERT INTO 员工信息(姓名,员工编号) VALUES('" + xingming + "','"+bianhao+ "')";
                save_Command.ExecuteNonQuery();
                offier_connection.Close();
写入一次数据之后,可以从access数据库中看到新插入的数据,可是关掉调试画面,重新打开再插入其他数据,会把之前插入的数据抹掉,只留下最后一次插入的数据,请问什么原因?
谢谢!!!
搜索更多相关主题的帖子: access insert 
2013-04-04 17:56
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
虽然我没事试你这段代码,但看起来至少这段代码并没有什么问题,而且你第一次都能插进去,并且在数据库中看到插入的数据.
你因该还有其它的代码没有贴出来吧,那你找找你代码中有没有delete语句,看看是不是在什么地方被误调用到了
2013-04-06 13:41
weilight2008
Rank: 1
等 级:新手上路
帖 子:111
专家分:4
注 册:2005-10-5
收藏
得分:0 
回复 楼主 weilight2008
我的完整代码是这样的:
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
namespace officer
{
    public partial class Form_luru : Form
    {
        public Form_luru()
        {
            InitializeComponent();
         
        }
        private void Form_luru_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“officerDataSet.员工信息”中。您可以根据需要移动或移除它。
            //this.员工信息TableAdapter.Fill(this.officerDataSet.员工信息);
     

        }
        private void button_luru_baocun_Click(object sender, EventArgs e)
        {
            string xingming = this.xingming.Text;
            string bianhao = this.bianhao.Text;
            string xingbie = this.comboBox1.Text;
            string nianyue = this.nianyue.Text;
            string jiguan = this.jiguan.Text;
            string mianmao = this.mianmao.Text;
            string id = this.id.Text;
            string school = this.school.Text;
            string zhuanye = this.zhuanye.Text;
            string xueli = this.xueli.Text;
            string time = this.time.Text;
            string hunyin = this.hunyin.Text;
            string chushi = this.chushi.Text;
            string shouji = this.shouji.Text;
            string dianhua = this.dianhua.Text;
            string email = this.email.Text;
            string zhiwu = this.zhiwu.Text;
            string zhicheng = this.zhicheng.Text;
            string jilu = this.jilu.Text;
            if (xingming == "" ||bianhao  == "")
            {
                MessageBox.Show("带“*”部分为必填内容,请补充完整!", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            try
            {              

                OleDbConnection officer_connection = new OleDbConnection();
                officer_connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=officer.mdb";
              
                officer_connection.Open();
              // /*
                OleDbCommand save_Command = officer_connection.CreateCommand();
                save_ = "INSERT INTO 员工信息(姓名,员工编号,性别,出生年月,籍贯,政治面貌,身份证号,毕业院校,所学专业,最高学历,入职时间,婚姻状况,处室,手机,办公电话,邮箱,职务,职称,工作记录) VALUES('" + xingming + "','" + bianhao + "','" + xingbie + "','" +nianyue + "','" + jiguan + "','" + mianmao + "','" + id + "','" + school + "','" + zhuanye + "','" + xueli + "','" + time + "','" + hunyin + "','" + chushi + "','" +shouji + "','" +dianhua + "','" +email + "','" + zhiwu + "','" + zhicheng + "','" + jilu + "')";
                save_Command.ExecuteNonQuery();             
                officer_connection.Close();
                 //*/
                /*
                OleDbCommand save_command = new OleDbCommand();
                save_ = "INSERT INTO 员工信息(姓名,员工编号) VALUES('" + xingming + "','" + bianhao + "')";
                save_command.Connection = officer_connection;
                OleDbDataAdapter officer_adapeter = new OleDbDataAdapter();
                officer_adapeter.SelectCommand = save_command;
                officer_adapeter.Fill(officerDataSet,"员工信息");
                 */
                MessageBox.Show("输入成功!", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (Exception ee2)
            {
                MessageBox.Show(ee2.Message, "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void button_luru_quxiao_Click(object sender, EventArgs e)
        {
            this.Close();
        }
      
    }
}


生活不相信眼泪,勇敢去拼。
2013-04-06 14:06
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
这样是没有问题的,每次都可以插进去啊,至少我试的时候每次都插进去了
2013-04-06 14:22
快速回复:每次对access数据库执行insert命令,都会清除以前输入的数据,何故?
数据加载中...
 
   



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

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