• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Create access table with c#

Hi I need to create a table in an existing access data base.  My table will have an int id field which is an identity autoincrement, a datetime field and numeric(18,4).   This is easy to do in sqlserver, but I cant figure it out with access and ado.net.  Looking for a quick easy solution.

thanks,
al
0
vbal
Asked:
vbal
  • 6
  • 4
1 Solution
 
HeidarVCommented:
Hello al

write this:
CREATE TABLE table1 (id counter primary key, theDate DateTime, num decimal(18, 4))

i hope this helps

Heidar
0
 
vbalAuthor Commented:
Heidar,

Have you tried that?  I did and it does not work in my access db.

thanks
0
 
HeidarVCommented:
do you work with odbc or oledb?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
vbalAuthor Commented:
I am with oledb; however, I tried executing your statement in the query window of access and it did not work.
-thanks
0
 
HeidarVCommented:
if you want to execute it in access you should first enable [ansi 92] in options-tables/queries.
0
 
HeidarVCommented:
this worked:

void RunSql(OleDbConnection con)
{
      OleDbCommand com = new OleDbCommand("CREATE TABLE table1 (id counter primary key, theDate DateTime, num decimal(18, 4))", con);
      com.Connection.Open();
      try
      {
            com.ExecuteNonQuery();
      }
      finally
      {
            com.Connection.Close();
      }
}
0
 
vbalAuthor Commented:
I will tru with ado.net as you say.  Will that create the id as autoincrement?

-thanks
0
 
HeidarVCommented:
yes
0
 
vbalAuthor Commented:
Works great, thanks.
-al
0
 
HeidarVCommented:
you are welcome
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now