Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everybody ,

I faced problem ..........incorrect syntax near 'ExperienceYear'

this is my code
C#
protected void Button1_Click(object sender, EventArgs e)
{
    SqlConnection conn = new SqlConnection("Data Source=vaio-pc\\SQLEXPRESS;Initial Catalog=JobDatabase;Integrated Security=True;Pooling=False");
    SqlCommand mycomm = new SqlCommand();
    StringBuilder sSQl= new StringBuilder();
    sSQl.Append( "Insert into [Imployee info]([F.Name],[L.Name],Email,Country,Gender,MaritalStatus,BirthDay");
    sSQl.Append("HomeNumber,CellPhoneNumber,GraduationYear,EducationalLevel,Field,SpecialIn ");
    sSQl.Append("ExperienceYears,Language,SoftSkill,GraduationGrade,LastSalary,ExpectedSalary,JobDescription");
    sSQl.Append("VALUES(@FName,@LName,@Email,@Country,@Gender,@MaritalStatus,@BirthDay,@HomeNumber");
    sSQl.Append("@CellPhoneNumber,@GradYear,@EduLevel,@Field,@SpecialIn,@ExpYear,@Language,@SoftSkill,@Grade");
    sSQl.Append("@LSalary,@ExpectSalary,@JobDesc");
    string strSql = sSQl.ToString();
    // bind the placeholder to the sources of information.
    mycomm.Parameters.AddWithValue("@FName", txtFirstName.Text);
    mycomm.Parameters.AddWithValue("@LName", txtLastName.Text);
    mycomm.Parameters.AddWithValue("@Email", txtEmail.Text);
    mycomm.Parameters.AddWithValue("@Country",CountryDownList.SelectedValue);
    mycomm.Parameters.AddWithValue("@Gender", GenderList.SelectedValue);
    mycomm.Parameters.AddWithValue("@MaritalStatus", MStateList.SelectedValue);
    mycomm.Parameters.AddWithValue("@BirthDay", txtBirthDay.Text);
    mycomm.Parameters.AddWithValue("@HomeNumber", txtHomeNum.Text);
    mycomm.Parameters.AddWithValue("@CellPhoneNumber", txtCellPhone.Text);
    mycomm.Parameters.AddWithValue("@GradeYear",GradeDownList.SelectedValue);
    mycomm.Parameters.AddWithValue("@EduLevel", txtEducationLevel.Text);
    mycomm.Parameters.AddWithValue("@Filed", FieldList.SelectedValue);
    mycomm.Parameters.AddWithValue("@SpecialIn", SpecialList.SelectedValue);
    mycomm.Parameters.AddWithValue("@ExpYear",Convert.ToInt16( txtExperienceYear.Text));
    mycomm.Parameters.AddWithValue("@Language", txtLanguage.Text);
    mycomm.Parameters.AddWithValue("@SoftSkill", SoftSkillListBox.SelectedValue);
    mycomm.Parameters.AddWithValue("@Grade", GradeDownList.SelectedValue);
    mycomm.Parameters.AddWithValue("@LSalary", txtLastSalary.Text);
    mycomm.Parameters.AddWithValue("@ExpectSalary", txtExpectedSalary.Text);
    mycomm.Parameters.AddWithValue("@JobDesc", txtJobDesc.Text);

    mycomm.CommandText = strSql;
    mycomm.Connection = conn;


    conn.Open();
    mycomm.ExecuteNonQuery();
    conn.Close();
    //I put  the table application in panel and when the operation of saving succeed .... the panel dissappear
    // and the label with text property "Congratulations!!! Your data has entered" appear
    EmpApplication.Visible = false;
    Finish.Visible = true;



and this is the exception


Server Error in '/Job website' Application.
Incorrect syntax near 'ExperienceYears'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'ExperienceYears'.

Source Error:


Line 54:
Line 55: conn.Open();
Line 56: mycomm.ExecuteNonQuery();
Line 57: conn.Close();
Line 58: //I put the table application in panel and when the operation of saving succeed .... the panel dissappear


Source File: c:\Users\vaio\Documents\Visual Studio 2010\WebSites\Job website\EmployeeApplication.aspx.cs Line: 56

Stack Trace:


[SqlException (0x80131904): Incorrect syntax near 'ExperienceYears'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1958954
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4876443
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1121
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +200
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +175
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
EmployeeApplication.Button1_Click(Object sender, EventArgs e) in c:\Users\vaio\Documents\Visual Studio 2010\WebSites\Job website\EmployeeApplication.aspx.cs:56
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Posted
Comments
[no name] 22-Sep-13 9:39am    
Yes ..... and? Simply examining the resulting SQL when you run it in your debugger would have shown you exactly what the problem was with your query.

C#
sSQl.Append("HomeNumber,CellPhoneNumber,GraduationYear,EducationalLevel,Field,SpecialIn ");
        sSQl.Append("ExperienceYears,Language,SoftSkill,GraduationGrade,LastSalary,ExpectedSalary,JobDescription");


Take a look at these two lines. There is a space between SpecialIn and ExperienceYears, but no comma.
 
Share this answer
 
This is a very easy problem to solve. All you had to do was put a breakpoint on your first mycomm.Parameter line and then run your application. When it hits that breakpoint it'll stop on that line. Then you hover the mouse over the strSql variable (it doesn't matter where) and you'll get the opportunity to examine the contents of the variable. Look at the SQL statement you built.

As Ron already said, you're missing a comma, exactly where the error message told you it should be.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900