c# - Check for MS Access database table if not exist create it -


how programmatically check ms access database table, if not exist create it?

simply execute following code if table exist return error other wise create new one:

try {         oledbconnection myconnection = new oledbconnection("provider=microsoft.jet.oledb.4.0; data source=" + frmmain.strfilepath + "\\configstructure.mdb");         myconnection.open();         oledbcommand mycommand = new oledbcommand();         mycommand.connection = myconnection;         mycommand.commandtext = "create table <yourtable name>(<columns>)";         mycommand.executenonquery();         mycommand.connection.close(); } catch(oledbexception e) {       if(e.errorcode == 3010 || e.errorcode == 3012)     // if error table exist processing required } 

those error codes returned if table exists - check here all.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -