我得到 sqlException 未处理。'nvarchar' 附近的语法不正确和 'Name' 附近的语法不正确。我使用 SMO 创建了一个这样的表
Table TechOpsProjectTracker = new Table(db, "TechOpsProjectTracker");
//Add column ID
DataType dt = new DataType(SqlDataType.Int);
Column idColumn = new Column(TechOpsProjectTracker, "ID", dt);
TechOpsProjectTracker.Columns.Add(idColumn);
//Add Column Alignment
DataType dt1 = new DataType(SqlDataType.NVarChar, 50);
Column Column1 = new Column(TechOpsProjectTracker, "Alignment", dt1);
TechOpsProjectTracker.Columns.Add(Column1);
//Add Column Project Name
DataType dt2 = new DataType(SqlDataType.NVarChar, 50);
Column Column2 = new Column(TechOpsProjectTracker, "Project Name", dt2);
TechOpsProjectTracker.Columns.Add(Column2);
//Add Column Project Description
DataType dt3 = new DataType(SqlDataType.NVarChar, 255);
Column Column3 = new Column(TechOpsProjectTracker, "Project Description", dt3);
TechOpsProjectTracker.Columns.Add(Column3);
//Add Column Currently Assigned To
DataType dt4 = new DataType(SqlDataType.NVarChar, 50);
Column Column4 = new Column(TechOpsProjectTracker, "Currently Assigned To", dt4);
TechOpsProjectTracker.Columns.Add(Column4);
TechOpsProjectTracker.Create();
string connectionString = "Server=GSOPS4;Database=MyDatabaseName;Trusted_Connection=True;";
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(connectionString);
System.Data.SqlClient.SqlCommand cmd =
new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT TechOpsProjectTracker (ID, Alignment, Project Name, Project Description, Currently Assigned To ) VALUES (@ID, @Alignment, @Project Name, @Project Description, @Currently Assigned To)";
SqlParameter ID = new SqlParameter("@ID", SqlDbType.Int);
ID.Value = 5;
cmd.Parameters.Add(ID);
SqlParameter Alignment = new SqlParameter("@Alignment", SqlDbType.NVarChar, 50);
Alignment.Value = "Right";
cmd.Parameters.Add(Alignment);
SqlParameter ProjectName = new SqlParameter("@Project Name", SqlDbType.NVarChar, 50);
ProjectName.Value = "Right Project Name";
cmd.Parameters.Add(ProjectName);
SqlParameter ProjectDesc = new SqlParameter("@Project Description", SqlDbType.NVarChar, 255);
ProjectDesc.Value = "Right Project Description";
cmd.Parameters.Add(ProjectDesc);
SqlParameter Assignment = new SqlParameter("@Alignment", SqlDbType.NVarChar, 50);
Assignment.Value = "corp\\shress2";
cmd.Parameters.Add(Assignment);
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
我得到这些异常的cmd.ExecuteNonQuery();
任何原因可能是什么原因造成的?TIA