create access table

D

Dave

I'm using the following code to add tables to an access database,

chkTables = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\\test.mdb" );
chkTables.Open();

string commandString = "CREATE TABLE Payments_Commis (ID Guid
Primary Key, Pay_Date DateTime, Company_no Text (255), Ab Long, Description
Text(255), Amount DOUBLE )";
OleDbCommand commMake = new OleDbCommand(commandString,
chkTables);
commMake.ExecuteNonQuery();

This works fine, but I would like to know how to add a AutoNumber field, and
how to set the double field Amount to 2 decimal places. The folowing does not
work

string commandString = "CREATE TABLE Payments_Commis (ID Guid AutoNumber,
Pay_Date DateTime, Company_no Text (255), Ab Long, Description Text(255),
Amount DOUBLE (2))";

both give errors.
 
J

Jeff Gaines

This works fine, but I would like to know how to add a AutoNumber field,
and
how to set the double field Amount to 2 decimal places. The folowing does
not
work

I think you need:

createString += " CONSTRAINT [pk_AutoId] PRIMARY KEY (RecordNumber)) ";

I have copied this from some code which creates a table from fields in a
ListView so it's a bit much to copy the whole thing here but that gets
tacked on to the end of the createString.

Change RecordNumber to the name of your autonumber field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top