Table creation from ADO.Net

R

Ray Valenti

I'm trying to create a SQL Server table via ado.net by running:

cmd.CommandType = CommandType.Text
cmd.CommandText = sql
cmd.ExecuteNonQuery()

Where:

SQL = "CREATE TABLE [DeracinateTemp]
([ID] [int] IDENTITY (1, 1) NOT NULL ,
....
[ContactDate] [datetime] NULL ,
CONSTRAINT [PK_DeracinateTemp] PRIMARY KEY CLUSTERED
(
[ID]()
) ON [PRIMARY]
) ON [PRIMARY]

I get the error:
Line 20: Incorrect syntax near '('.
System.Data.SqlClient.SqlException: Line 20: Incorrect syntax near '('.
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

line 20 is the [ID]() line.

This runs fine in Query Analyzer but not in ADO.net
Is a different syntax required from code?

Ray
 
R

Raymond Lewallen

Ray,

Try this:

SQL = "CREATE TABLE [DeracinateTemp]" & _
"([ID] [int] IDENTITY (1, 1) NOT NULL " & _
"CONSTRAINT [PK_DeracinateTemp] PRIMARY KEY CLUSTERED,
"..." & _
"[ContactDate] [datetime] NULL" & _
") ON [PRIMARY]"

HTH,

Raymond Lewallen
 

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