Last post May 04, 2008 03:42 AM by gr33nhorn
Apr 21, 2008 05:42 AM|haimohi|LINK
How can I create the Access database and tables at run time using c#?
Apr 21, 2008 06:51 AM|johram|LINK
Perhaps this link is helpful:
Create Access Database in C#
Apr 21, 2008 08:41 AM|haimohi|LINK
Thanks for your help. I followed that link and could create the Database. Can you please tell me how to create the tables and create the constraints to the tables at run time?
Apr 21, 2008 09:45 AM|johram|LINK
OleDbConnection conn = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand("CREATE TABLE Sometable ([Id] COUNTER, [Column1] TEXT(10), [Column2] TEXT(6))", conn);
Apr 21, 2008 03:01 PM|Mikesdotnetting|LINK
Can you please tell me how to create the tables and create the constraints to the tables at run time?
There's a nice series of articles on Jet SQL and Data Definition Language (DDL) here:
http://msdn.microsoft.com/en-us/library/aa140011(office.10).aspx. You could also use ADOX to create the tables etc (as you did the database), but DDL is a lot easier to work
Apr 22, 2008 01:34 AM|haimohi|LINK
Thanks for your help. I am trying to connect the MS Access 2007 Database. Database Extension of the MS Access 2007 shows accdb.
My connection string is like this
When i tried to open the connection i got an error "Could not find installable ISAM."
Can You please help this?
Apr 22, 2008 02:43 AM|johram|LINK
The connection strings for MS Access 2007 is different from those targeted for earlier versions.
See this great reference for an example:
I always go to this site for copy-pasteable connection strings.
Apr 22, 2008 02:57 AM|haimohi|LINK
Thank you very much. It works now.
May 04, 2008 03:35 AM|gr33nhorn|LINK
I have to create table that uses name given by user at runtime from a textbox the code i tried was
OleDbCommand command = new OleDbCommand("CREATE TABLE '"+textBox1.Text+"' ([Id] TEXT(10), [Column1] TEXT(10), [Column2] TEXT(6))", dbConnection);
but this shows syntax error
Access database query string
May 04, 2008 03:39 AM|johram|LINK
You don't surround the table name with '
Also you should never use the value from a textbox directly like this, as it opens up for SQL injection which is a major security threat. Always use parametrized queries.
If you have more questions, please start a new thread as this thread is already closed.
May 04, 2008 03:42 AM|gr33nhorn|LINK