Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

create a runtime table in Ms Access database

I want to create table at runtime for an existing Ms Access database using ASP.net 2.0 and C#.
Can anyone please guide me through it ?
[139 byte] By [arpd2005] at [2007-11-11 10:00:04]
«« CardLayout
»» Images
# 1 Re: create a runtime table in Ms Access database
See the below newsgroup post. You may also want to take a look some Jet SQL DDL articles:

http://tinyurl.com/y6vq5j

http://msdn2.microsoft.com/en-us/library/aa140011(office.10).aspx
http://msdn2.microsoft.com/en-us/library/aa140015(office.10).aspx
pclement at 2007-11-11 23:12:14 >
# 2 Re: create a runtime table in Ms Access database
void createTable(string connString, string tableName)
{
try
{
OleDbConnection con = new OleDbConnection(connString);
OleDbCommand cmd = con.CreateCommand();

string cmdText = String.Format("CREATE TABLE {0} (dno int primary key, dname char(15), grade int, avg int)",tableName);

cmd.CommandType = CommandType.Text;
cmd.CommandText = cmdText;
con.Open();

cmd.ExecuteNonQuery();
}
catch (Exception e)
{
// Process error
log.Error("Exception occured", e);
}
finally
{
// Close connection if open

try { if (con != null) con.Close(); }
catch (Exception ex)
{
log.Warn("Unable to close connection - exception occured.", ex);
}
}
}
arpd2005 at 2007-11-11 23:13:14 >