2 Replies - 2821 Views - Last Post: 30 November 2012 - 10:09 PM Rate Topic: -----

#1 purvabhilare1587  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 27-May 12

Incorrect syntax near keyword 'values'

Posted 30 November 2012 - 04:05 AM

Hi,

I am trying to insert values to a table in sql.I get the following error : Incorrect syntax near keyword 'values'.
I am using sql server 2008 r2.Following is my code.

If ProductTypeComboBox.Text = "REPAIR(INHOUSE)" Then
         

            Using sqlcon As New SqlConnection(My.Settings.Hardware_DatabaseConnectionString)

                ' Dim sqlcon As New SqlConnection(My.Settings.Hardware_DatabaseConnectionString)
                sqlcon.Open()
                Dim sqlCmd As New SqlCommand("insert into Product_Table([Prd_Sr_Key_No],[Prd_Name],[Prd_Brand],[Prd_Type],[Prd_Detail],[Dte_Stck_In],[Brght_By],[Note],[Prd_Data_Crtd_By],[Prd_Data_Crtd_Date] Values(@srkeyno,@prdname,@prdbrand,@prdtype,@prddetail,@dtestckin,@brghtby,@note,@prddatacrtdby,@prddatacrtddate)", sqlcon)

                sqlCmd.Parameters.AddWithValue("@srkeyno", Trim(SrKeyNoTextBox.Text))
                sqlCmd.Parameters.AddWithValue("@prdname", Trim(ProductNameTextBox.Text))
                sqlCmd.Parameters.AddWithValue("@prdbrand", BrandNameComboBox.Text)
                sqlCmd.Parameters.AddWithValue("@prdtype", ProductTypeComboBox.Text)
                sqlCmd.Parameters.AddWithValue("@prddetail", DetailRichTextBox.Text)
                sqlCmd.Parameters.AddWithValue("@dtestckin", ddComboBox.Text + "/" + mmComboBox.Text + "/" + yyyyComboBox.Text)
                sqlCmd.Parameters.AddWithValue("@brghtby", Trim(BroughtByTextBox.Text))
                sqlCmd.Parameters.AddWithValue("@note", NoteRichTextBox.Text)
                sqlCmd.Parameters.AddWithValue("@prddatacrtdby", Trim(CreatedByProdTextBox.Text))
                sqlCmd.Parameters.AddWithValue("@prddatacrtddte", CreatedDateProdddComboBox.Text + "/" + CreatedDateProdmmComboBox.Text + "/" + CreatedDateProdyyComboBox.Text)
                sqlCmd.ExecuteNonQuery()
                MsgBox("Data added successfully")
            End Using
        
        Else
            MsgBox("Input is other than REPAIR(INHOUSE)")
        End If



Is This A Good Question/Topic? 0
  • +

Replies To: Incorrect syntax near keyword 'values'

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Incorrect syntax near keyword 'values'

Posted 30 November 2012 - 06:11 AM

It's been many years since I used SQL, but here's a possibility:

I think there should be a ) before the Values keyword, and perhaps no square brackets. Try:
"insert into  Product_Table(Prd_Sr_Key_No,Prd_Name,Prd_Brand,Prd_Type,Prd_Detail,Dte_Stck_In,Brght_By,Note,Prd_Data_Crtd_By,Prd_Data_Crtd_Date)  Values(@srkeyno,@prdname,@prdbrand,@prdtype,@prddetail,@dtestckin,@brghtby,@note,@prddatacrtdby,@prddatacrtddate)"


Was This Post Helpful? 0
  • +
  • -

#3 purvabhilare1587  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 27-May 12

Re: Incorrect syntax near keyword 'values'

Posted 30 November 2012 - 10:09 PM

View Postlar3ry, on 30 November 2012 - 06:11 AM, said:

It's been many years since I used SQL, but here's a possibility:

I think there should be a ) before the Values keyword, and perhaps no square brackets. Try:
"insert into  Product_Table(Prd_Sr_Key_No,Prd_Name,Prd_Brand,Prd_Type,Prd_Detail,Dte_Stck_In,Brght_By,Note,Prd_Data_Crtd_By,Prd_Data_Crtd_Date)  Values(@srkeyno,@prdname,@prdbrand,@prdtype,@prddetail,@dtestckin,@brghtby,@note,@prddatacrtdby,@prddatacrtddate)"




Hey thnx its working.The closing round bracket before the keyword 'VALUES' was missing.
and I didn't remove the square brackets.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1