[英]Oledbconnection to Access Database C#
I face some problem: 我遇到一些问题:
I can insert data to my database by following code: 我可以通过以下代码将数据插入数据库:
oledbconnection = new oledbconnection (@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\User\yourdbfile.accdb");
the data was successfully insert to my database, 数据已成功插入到我的数据库中,
but if i change the code to 但是如果我将代码更改为
oledbconnection = new oledbconnection (@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=yourdbfile.accdb");
OR 要么
oledbconnection = new oledbconnection (@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\yourdbfile.accdb");
I'm unable to insert data to database, and there is no error. 我无法将数据插入数据库,并且没有错误。
Another Question, 另一个问题,
How can i publish my system with database file? 如何使用数据库文件发布系统? because when i installed this system on another pc, the error show C:\\User\\yourdbfile.accdb
not found. 因为当我在另一台PC上安装此系统时,错误显示未找到C:\\User\\yourdbfile.accdb
。
您可以将db源文件放入应用程序文件夹中,例如:install disk folder:d:\\ AA \\ BB \\,DB文件:D:\\ AA \\ BB \\ DB file \\
You can check for the Property of the Access file on its Build property value. 您可以在其Build属性值上检查Access文件的Property。
OR 要么
Modifying your ProjectName.csproj is a better way to over come with this problem. 修改ProjectName.csproj是解决此问题的一种更好的方法。 See details below: 请参阅以下详细信息:
<Target Name="AfterBuild">
<Copy SourceFiles="$(OutputPath)yourdbfile.accdb" DestinationFolder="$(YourVariable)" ContinueOnError="true" />
</Target>
See this link for your reference. 请参阅此链接以供参考。
After checking those things, You can now use: 检查完这些内容后,您现在可以使用:
var oledbconnection = new Oledbconnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdbfile.accdb");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.