In my Winforms app, I'm trying to programmatically create a local SQL table with this code:
using (var connection = new
using (var command = connection.CreateCommand())
StringBuilder sb = new StringBuilder();
sb.Append("CREATE TABLE [dbo].[AssignmentHistory] ");
sb.Append("[Id] INT NOT NULL PRIMARY KEY ");
sb.Append("[WeekOfAssignment] DATE NOT NULL ");
sb.Append("[TalkType] INT NOT NULL ");
sb.Append("[StudentID_FK] INT NOT NULL FOREIGN KEY ");
sb.Append("[AssistantID_FK] INT NOT NULL FOREIGN KEY ");
sb.Append("[CounselPoint] INT NOT NULL");
command.CommandText = sb.ToString();
//catch (SqlException sqlex) <= SqlException not
catch (Exception ex)
...but I'm getting, "Incorrect syntax near WeekOfAssignment"
What is wrong with the syntax there? I derived this code from what I gleaned from here.
This is a "local" db, based on "Service-based database" as shown in the link above; if it makes any difference, I'm using VS 2015 Community.