ADOX problem
-
hello all i am trying to serialize an access database into xml file then recreate the database again from the xml file, i ma using "Microsoft ADO Ext. 2.8 for DDL and Security" here is a sample code of recreating the database from the xml file. DS2 = new DataSet(); DS2.ReadXml(Application.StartupPath + @"\DataSet.xml"); DataTable temp = DS2.Tables[0]; string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application.StartupPath+@"\DataSet.mdb"; ADOX.CatalogClass cat = new CatalogClass(); cat.Create(strConn + "; Jet OLEDB:Engine Type = 5"); cat.Tables.Append((Object)temp); cat=null; but i got a com exception says "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another". can anyone help?
-
hello all i am trying to serialize an access database into xml file then recreate the database again from the xml file, i ma using "Microsoft ADO Ext. 2.8 for DDL and Security" here is a sample code of recreating the database from the xml file. DS2 = new DataSet(); DS2.ReadXml(Application.StartupPath + @"\DataSet.xml"); DataTable temp = DS2.Tables[0]; string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application.StartupPath+@"\DataSet.mdb"; ADOX.CatalogClass cat = new CatalogClass(); cat.Create(strConn + "; Jet OLEDB:Engine Type = 5"); cat.Tables.Append((Object)temp); cat=null; but i got a com exception says "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another". can anyone help?
From the code, I understand that you are trying to create table in access from the dataset but your approach is not acceptable for ADOX. In a similar task, I have tried to export my dataset to an mdb database and I had to construct SQL commands from the dataset to create and insert data. I think this one can give you a starting point. Here is my create table method:
/// /// Constructs the required SQL Query to create the tables in mdb database and then executes the query. /// private void CreateTables() { string sqlCommand = "CREATE TABLE "; foreach (DataTable dTable in currentDataSet.Tables) { string sqlCreate = sqlCommand + dTable.TableName + "("; int cnt = 0; foreach (DataColumn dColumn in dTable.Columns) { string sqlCreateCommand = sqlCreate + dColumn.ColumnName; if (cnt != dTable.Columns.Count - 1) { cnt++; sqlCreateCommand += GetDataType(dColumn) + ", "; } if (dTable.Columns.IndexOf(dColumn) == dTable.Columns.Count - 1) { cnt++; sqlCreateCommand += GetDataType(dColumn) + ");"; } sqlCreate = sqlCreateCommand; } OleDbCommand dbCommand = new OleDbCommand(sqlCreate, (OleDbConnection)dsConnection.CurrentDbConnection); dbCommand.ExecuteNonQuery(); }
Always keep the Murphy Rules in mind!