I need to create a table in MS access database. Consider, ‘ConfigStructure.mdb’ being my database name and i need to create a table in this database in C#.
How can i do this? I tried with the below code but its not working.
OleDbConnection myConnection = new OleDbConnection('Provider=Microsoft.Jet.OLEDB.4.0; Data Source=' + frmMain.strFilePath + '\\ConfigStructure.mdb'); myConnection.Open(); string strTemp = ' KEY Text, VALUE Text '; OleDbCommand myCommand = new OleDbCommand(); myCommand.Connection = myConnection; myCommand.CommandText = 'CREATE TABLE table1(' + strTemp + ')'; myCommand.ExecuteNonQuery(); myCommand.Connection.Close();
This is the error that i get,
'System.Data.OleDb.OleDbException: Syntax error in field definition System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)\r\n at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)\r\n at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)\r\n at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)'
Replace
with
I think the reason for this is that ‘KEY’ an ‘VALUE’ are reserved keywords in Access or SQL.