如何将数据插入到Microsoft Access数据库? [英] How to insert data into a Microsoft Access Database?

查看:146
本文介绍了如何将数据插入到Microsoft Access数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将数据插入到Microsoft Access数据库。

余插入数据到Access数据库,但在第一和第二时间是显示我插入的数据的唯一次。当我重建我的应用程序,我插入的数据已经一去不复返了。我不知道他们去哪里,而不是表演。我使用C#与.NET框架开发。下面是的code中的相关部分:

  OleDbConnection的CON =新的OleDbConnection(ConfigurationManager.ConnectionStrings [|构造]的ConnectionString。);
OleDbCommand的COM =新的OleDbCommand();
com.Connection = CON;
com.CommandText =插入到语言(英语,类型,泰国)的值(@ ENG,@类,@泰);
com.Parameters.AddWithValue(@ ENG,英语);
com.Parameters.AddWithValue(@类型,输入);
com.Parameters.AddWithValue(@泰,泰文);
con.Open();
com.ExecuteNonQuery();
 

我写了code,但我认为这是奇怪的。它不显示任何错误或异常,但我的数据是不正确插入。这是将数据插入正确的方法是什么?如果是这样,为什么它没有得到插?

解决方案
  

当我重建我的应用程序,我插入的数据已经一去不复返了。

我怀疑,当应用程序被重新构建你的数据库被覆盖。

这可能发生,例如,如果你的应用程序包含被复制到构建输出目录中的MDB文件,并从输出目录中。

I'm trying to insert data into a Microsoft Access Database.

I inserted data into the Access database, but the first and second time are the only times that show the data I inserted. When I rebuild my application, the data I inserted is gone. I don't know where they go and not show. I use C# with the .NET framework to develop. Here's the relevant part of the code:

OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString);
OleDbCommand com = new OleDbCommand();
com.Connection = con;
com.CommandText = "Insert into Language(English,Type,Thai) values(@eng,@type,@thai)";
com.Parameters.AddWithValue("@eng", english);
com.Parameters.AddWithValue("@type", type);
com.Parameters.AddWithValue("@thai", thai);
con.Open();
com.ExecuteNonQuery();

I wrote that code, but I think it is strange. It doesn't show any errors or exceptions, but my data is not inserted correctly. Is this the correct way to insert data? If so, why it it not getting inserted?

解决方案

When I rebuild my application, the data I inserted is gone

I suspect your database is being overwritten when the application is rebuilt.

This can happen, for example, if your application contains an MDB file that is copied to the output directory on build, and is used from the output directory.

这篇关于如何将数据插入到Microsoft Access数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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