I am new to C# and I am developing an application that uses a small Access database. I tried to understand what to use, ADODB or OLEDB, but it seems I was unable to solve the question.
So, is it possible use only one of these libraries? Or it is normal use both?
For example, the usual stuff with databases:
string MyQuery = "SELECT * FROM MyTable";
Recordset rs = new Recordset();
rs.Open(MyQuery, MyConnection, CursorTypeEnum.adOpenKeyset, LockTypeEnum.adLockOptimistic);
uses all ADODB objects, until:
OleDbDataAdapter adapter = new OleDbDataAdapter();
DataTable dt = new DataTable("MyTable");
adapter.Fill(dt, rs);
so I feed a DataGridView with the Datatable. The adapter is OLEDB, not ADODB. Is there a way to avoid OLEDB? So, I thought I got rid of ADODB and do everything in OLEDB, all went well until I wanted add tables at runtime:
ADOX.Catalog MyCat = new ADOX.Catalog();
MyCat.ActiveConnection = MyConnection;
ADOX.Table table = new ADOX.Table();
table.Name = "MyTable";
table.Columns.Append("ID", ADOX.DataTypeEnum.adInteger);
table.Columns["ID"].ParentCatalog = MyCat;
table.Columns["ID"].Properties["AutoIncrement"].Value = true;
table.Keys.Append("PrimaryKey", ADOX.KeyTypeEnum.adKeyPrimary, "ID");
table.Columns.Append("DateAdded", ADOX.DataTypeEnum.adDate);
table.Columns.Append("Name");
table.Columns.Append("Surname");
cat.Tables.Append(table);
where the catalog absolutely refuses an OLEDB connection and demands an ADODB one so I needed to rescue ADODB.
So, in the end, do I need to resign to use both or I am doing something wrong in the code samples I posted? Alternatives are welcomed, thanks in advance.
It would very nice for a newbie know which system to use and stick with it, knowing it can do everything it needs to be done.