首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >执行insert查询后,MDB中未插入任何数据

执行insert查询后,MDB中未插入任何数据
EN

Stack Overflow用户
提问于 2012-10-04 15:11:28
回答 1查看 497关注 0票数 0

当我尝试在MS Access数据库中插入某些数据时,数据未插入。我的代码中是否遗漏了什么?

这是代码

代码语言:javascript
复制
public void Toevoegen(
        int nummer, string voornaam, string achternaam, 
        string gsm, string nationaliteit, string adres, 
        DateTime geboorteDatum, string geboortePlaats, DateTime inschrijvingsDatum, 
        string sporten, int postCode, string gemeente, string klasse,
        Boolean competitie, string ziektes, string email)
    {
        try
        {
            string query = @"INSERT INTO Lid "
                + "VALUES ("
                + "@Lid_ID, "
                + "@Lid_VoorNaam, "
                + "@Lid_AchterNaam, "
                + "@Lid_Email, "
                + "@Lid_GeboorteDatum, "
                + "@Lid_InschrijvingsDatum, "
                + "@Lid_Nationaliteit, "
                + "@Lid_GeboortePlaats, "
                + "@Lid_Adres, "
                + "@Lid_PostCode, "
                + "@Lid_Gemeente, "
                + "@Lid_GSM, "
                + "@Lid_BeoefendeSporten, "
                + "@Lid_Competitie, "
                + "@Lid_KickKlasse, "
                + "@Lid_Ziektes)";

            OleDbCommand command = new OleDbCommand(query);
            command.Parameters.Add("@Lid_ID", OleDbType.Numeric).Value = nummer;
            command.Parameters.Add("@Lid_VoorNaam", OleDbType.Char).Value = voornaam;
            command.Parameters.Add("@Lid_Achternaam", OleDbType.Char).Value = achternaam;
            command.Parameters.Add("@Lid_Email", OleDbType.Char).Value = email;
            command.Parameters.Add("@Lid_GeboorteDatum", OleDbType.Date).Value = geboorteDatum;
            command.Parameters.Add("@Lid_InschrijvingsDatum", OleDbType.Date).Value = inschrijvingsDatum;
            command.Parameters.Add("@Lid_Nationaliteit", OleDbType.Char).Value = nationaliteit;
            command.Parameters.Add("@Lid_GeboortePlaats", OleDbType.Char).Value = geboortePlaats;
            command.Parameters.Add("@Lid_Adres", OleDbType.Char).Value = adres;
            command.Parameters.Add("@Lid_PostCode", OleDbType.Numeric).Value = postCode;
            command.Parameters.Add("@Lid_Gemeente", OleDbType.Char).Value = gemeente;
            command.Parameters.Add("@Lid_GSM", OleDbType.Char).Value = gsm;
            command.Parameters.Add("@Lid_BeoefendeSporten", OleDbType.Char).Value = sporten;
            command.Parameters.Add("@Lid_Competitie", OleDbType.Boolean).Value = competitie;
            command.Parameters.Add("@Lid_KickKlasse", OleDbType.Char).Value = klasse;
            command.Parameters.Add("@Lid_Ziektes", OleDbType.Char).Value = ziektes;
            conn.executeInsertQuery(command);
        }
        catch (Exception error)
        {
            System.Windows.Forms.MessageBox.Show(error.Message);
        }
    }

--

代码语言:javascript
复制
public bool executeInsertQuery(OleDbCommand _command)
    {
        OleDbCommand myCommand = new OleDbCommand();
        try
        {
            myCommand.Connection = openConnection();
            //myCommand.CommandText = _query;
            //myCommand.Parameters.AddRange(dbParameter);
            myAdapter.InsertCommand = _command;
            myCommand.ExecuteNonQuery();
        }
        catch (OleDbException e)
        {
            Console.Write("Error - Connection.executeInsertQuery - Query: " 
                + _command.CommandText + " \nException: \n" + e.StackTrace.ToString());
            return false;
        }
        finally
        {
        }
        return true;
    }

提前谢谢你。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-04 15:14:57

问题将出现在这里:

代码语言:javascript
复制
myAdapter.InsertCommand = _command;
myCommand.ExecuteNonQuery();

您将命令分配给myAdapter,但随后执行为空的myCommand

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12722023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档