开发者

C# Read/Write into Access DB File

I want to write into Access Database File using C# Application, probably using WPF ... I also want the file to be password protected ... is it possible to connect to it while it is password protected开发者_JAVA技巧 or should I remove the password?


Use OleDbConnection (System.Data.OleDb) and the right connection string.

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;


Our C# .Net4.0 Windows Forms data connection to MS Access looks like this:

using System.Data.OleDb;
...
private void DoIt()
{
  OleDbConnection NamesDB = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=CyberSprocket.mdb");

  try
  {
     NamesDB.Open();
  }
  catch (Exception ex) {
      MessageBox.Show(ex.Message);
      return;
  }
  OleDbCommand NamesCommand = new OleDbCommand("SELECT * FROM [names];", NamesDB);
  OleDbDataReader dr = NamesCommand.ExecuteReader();

  string theColumns = "";
  for (int column = 0; column < dr.FieldCount; column++)
  {
    theColumns += dr.GetName(column) + " | ";
  }
  MessageBox.Show(theColumns);

  NamesDB.Close();
}


Yes you can work with a password protected MS Access Database.

In your connection string to MS Access database, you can provide a USERNAME and PASSWORD.

Depending on which Security type is implemented, here are two samples:

Workgroup Security using a System Database

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Server\Share\MyData.mdb;Jet OLEDB:System Database=\\Server\Share\MyData.mdw;USER=userid, PWD=password"

With Standard MS Access Security:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Server\Share\MyData.mdb;User ID=userid;Password=password;"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜