C#.NET读取的.mdb文件 [英] c# .net reading .mdb files

查看:2246
本文介绍了C#.NET读取的.mdb文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有必要对我来说,使用C#.NET,将编辑特定的.mdb文件编写应用程序。

It is necessary for me to write an application using C# .net that will edit specific .mdb files.

这纯粹是一个在部门应用程序读取,部门文件debateably不应该的.mdb文件,但我没有在这个问题的选择。我推动改变为XML文件,但是这是一个不同的问题。

It's purely an in-department application for reading in-department files that debateably shouldn't be .mdb files, but I don't have a choice in that matter. I am pushing for changing to XML files, but that's a different matter.

该文件与100ish非常有限,3ish表的记录每一个;所以我希望能够读取整个数据库到应用程序的特定对象。任何错误都会被忽略,一个新的数据库副本将覆盖previous之一。该数据库是一个非常具体的格式和容易的,我验证或扔出去。

The files are very much finite, 3ish tables with 100ish records each; so I hope to read the entire databases into application specific objects. Anything erroneous will be ignored and a new database copy will overwrite the previous one. The databases are a very specific format and easy for me to validate or throw out.

似乎有很多方法,实际上读/写在.NET多边开发银行已经离开我迷惑。任何人都可以提出一个最好的?

There seems to be many methods for actually reading/writing mdbs in .net which has left me confused. Can anyone suggest a best one?

推荐答案

您可以用这个code尝试 - 以 OLEDB提供

You can try with this code - based on Oledb provider

var mdb = "c:\MyDB.mdb"; 
var myDataTable = new DataTable(); 
using(var connection = new OleDbConnection(....."))
{ 

//Here sample format of string connection
//"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" 
//+ mdb + ";Mode=Share Deny None;Extended Properties='';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Engine Type=4;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False


connection.Open(); 
var query = "SELECT * from TABLE"; //Adjust your query

var adapter = new OleDbDataAdapter(query, connection); //This assigns the Select statement and connection of the data adapter 

OleDbCommandBuilder oleDbCommandBuilder = new OleDbCommandBuilder(adapter); //This builds the update and Delete queries for the table in the above SQL. this only works if the select is a single table. 

dadapt.Fill(MyDataTable); 

}

这篇关于C#.NET读取的.mdb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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