Reputation: 198
I can't get a connection to my database, I only receive a compiler error that DAOWorkSpace is unassigned... And the bigger problem is that I can't find any documentation for DAO in C#.
Yes i have to use DAO.
My code:
DAO.Database DAODataBase;
DAO.DBEngine DAODBEngine = new DAO.DBEngineClass();
DAO.Recordset DAOFoundCode;
DAO.Workspace DAOWorkSpace;
DAODataBase = DAOWorkSpace.OpenDatabase(mdbFile, null, null, ";pwd=");
I tried setting different arguments but I keep getting the same error.
I ran out of ideas. Help is appreciated since I'm stuck here.
Upvotes: 0
Views: 5288
Reputation: 198
The Answer:
private string InsertDescription( string mdbFile )
{
string log = null;
DAO.Database db;
DAO.DBEngine dbEn = new DAO.DBEngine();
DAO.Recordset rs;
string value = "Bi pe di Ba pe di Buuuuuuuuuuuuuuuuuuuuuuu!!!!";
string tabelName = "AC_Tab";
string columnName = "dbac3_ac_version_db";
try
{
db = dbEn.OpenDatabase(mdbFile, null, false, null);
rs = db.OpenTable(tabelName, 0);
rs.AddNew();
db.TableDefs[tabelName].Fields[columnName].Properties["Description"].Value = value;
rs.Update(1, false);
rs.Close();
log = "- Der Descriptionimport in die Datenbank war erfolgreich!";
}
catch( Exception ex )
{
log = "- Der Descriptionimport in die Datenbank war Nicht erfolgreich!" + Environment.NewLine + ex.Message;
}
return log;
}
Upvotes: 0
Reputation: 32642
You need to assign the workspace first:
DAOWorkSpace = DAODBEngine.Workspaces[0]; //Default workspace
Also, don't set the properties in OpenDatabase
to Null
DAODataBase = DAOWorkSpace.OpenDatabase(mdbFile, False, True, ";pwd="); //Shared mode, read-only
Upvotes: 2