Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7996453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:42:48+00:00 2026-06-04T14:42:48+00:00

I m getting sqlException was unhandled. Incorrect syntax near ‘nvarchar’ and Incorrect syntax near

  • 0

I m getting sqlException was unhandled. Incorrect syntax near ‘nvarchar’ and Incorrect syntax near ‘Name’. I used SMO to create a table like this

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();

I get those exceptions at cmd.ExecuteNonQuery();
Any reasons what might be causing it? TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:42:49+00:00Added an answer on June 4, 2026 at 2:42 pm

    There’s a couple of issues.

    Your INSERT statement has spaces in the column name, so you have to enclose those in brackets.
    Also, the parameter names cannot have spaces in them, so you need to stick the words together.

    cmd.CommandText = "INSERT TechOpsProjectTracker (ID, Alignment, [Project Name], [Project Description], [Currently Assigned To] ) VALUES (@ID, @Alignment, @ProjectName, @ProjectDescription, @CurrentlyAssignedTo)";
    

    Then, when you’re adding the parameters, same thing, stick the words together:

    SqlParameter ProjectName = new SqlParameter("@ProjectName", SqlDbType.NVarChar, 50);
    ProjectName.Value = "Right Project Name";
    cmd.Parameters.Add(ProjectName);
    
    
    SqlParameter ProjectDesc = new SqlParameter("@ProjectDescription", SqlDbType.NVarChar, 255);
    ProjectDesc.Value = "Right Project Description";
    cmd.Parameters.Add(ProjectDesc);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting following error in my query System.Data.SqlClient.SqlException: Incorrect syntax near the keyword
i was getting this error com.ibm.db2.jcc.b.SqlException: Invalid argument: unknown column name COL1 when trying
I getting a SqlException was unhandled error when I try to open the connection
I'm getting a sqlexception while im trying to select some values. The error: Incorrect
I'm getting this exception: com.ibm.db2.jcc.c.SqlException: The syntax of the string representation of a datetime
I am getting java.sql.SQLException: The column ID in table METAL_HAREKET_IPTAL does not allow null
Getting java.sql.SQLException java.sql.SQLException: General error at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6986) at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114) at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110) at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338) at
I'm getting a timeout error when trying to execute a LINQ (-to-SQL) query System.Data.SqlClient.SqlException:
I'm getting the SQLException Invalid Column Type whenever I try to use a parameter
I am getting the error: java.sql.SQLException: No suitable driver I have imported the .jar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.