nett

nett

  • NA
  • 7
  • 0

multiple sql statements in OLE DB command

Jun 12 2004 3:47 PM
I'm developing a C# application and using OleDb and ADO.NET to access a MS Access database. I'm relatively new at this stuff so I'm probably missing something simple. I would like to create a table and then alter another table to add a field and foreign key constraint. But the command fails when I combine the 2 SQL statements together (CREATE TABLE and ALTER TABLE). Everything works great when 2 commands are used. I've searched through help but can't find anything useful (e.g. command expression syntax). Any suggestions? Here's an example of what I've tried: BEGIN TRANSACTION CREATE TABLE Owners ( OwnerID INTEGER IDENTITY (1,1) NOT NULL, LastName CHAR(40) NULL, FirstName CHAR(40) NULL, CONSTRAINT PK_Owners PRIMARY KEY ( OwnerID ) ) ALTER TABLE Property ADD OwnerID INTEGER NULL, CONSTRAINT FK_Property_Owners FOREIGN KEY ( OwnerID ) REFERENCES Owners ( OwnerID ) COMMIT Thanks, Jerry

Answers (1)