質問

I was tasked with creating a simple API to access an MDB containing regional data (Region Name, Region ID, Country, etc). I have read about the Jet Engine but there is not a lot of good tutorials or documentation on it. I would like to build this API using the latest technology compatible with .NET 4.0. At first I thought I could use LINQ, but I cannot seem to be able to find anything concrete on it.

My question is:

What are the best methods of reading/writing to an MDB from .NET and where can I find good tutorials or documentation on it.

役に立ちましたか?

解決

I'm not sure MS has create a Linq provider for either ODBC or OLE. You might have to do it yourself, without anything fancy I'm afraid.

You could use Microsoft.Jet.OLEDB.4.0 as your provider. It's a long time since I've had to do this but, try something like (this is just stab here and I haven't tested this even compiles, but it shouldn't be too far off):

var connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Data.mdb";
var query = "select * from Regions";

using (var connection = new OleDbConnection(connectionString))
using (var command = new OleDbCommand(query))
{
    command.Connection = connection;
    connection.Open();

    var reader = command.ExecuteReader();
    while (reader.Read())
    {
        // Not 100% sure here..
        var regionName = (string)reader["regionName"];
    }

    connection.Close();
}

As far as a tutorial goes, not sure. I'd start with something like this, and go from there. Hope this gets you started.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top