Results 1 to 11 of 11

Thread: [RESOLVED] undiscclosed quotation mark after the character string')'.incorrect syntax near ')'.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    20

    Resolved [RESOLVED] undiscclosed quotation mark after the character string')'.incorrect syntax near ')'.

    when saving am getting this error"undiscclosed quotation mark after the character string')'.incorrect syntax near ')'.
    I used the command in other codes which working perfectly. Please help

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
    'Dim Table As New DataTable()
    put = "Insert into loans (msdDate_Applied, Loan_No,Prin_Amount,purpose,Account_no,loan_kind) values(" & msdDate_Applied.TextMaskFormat & ",'" & Me.txtLoan_no.Text & "','" & cboloan_kind.SelectedValue() & "','" & cbokind.Text & "'," & Me.txtprin_amount.Text & "')"
    da = New SqlDataAdapter(put, ConnectionString)
    da.Fill(ds, "user")
    MessageBox.Show("Record Successfully Added")
    Me.btnsave.Enabled = False
    End Sub

    thanks for ur help

  2. #2
    Addicted Member
    Join Date
    Sep 2009
    Location
    The Netherlands
    Posts
    148

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    hi,
    As far as I can see, in the code you provided:
    Code:
    ," & Me.txtprin_amount.Text & "'
    is missing the quotation mark:
    Code:
    ,'" & Me.txtprin_amount.Text & "'
    Paul

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    Don't use string concatenation to build SQL statements. It's just too error prone, as this issue shows, and is a big security hole too. Always use parameters. Follow the Blog link in my signature and read my post on ADO.NET parameters for the how and why.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    20

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    thanks for yours reply,
    After correcting the error, am getting the message 'cannot insert explicit value for identity column in the table 'loans' when IDENTITY_INSERT is set OFF
    da.fill(ds,"loans") highlighted

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    That means that your database is configured to generate ID values automatically and you're trying to insert an ID yourself. Don't include the ID column in the SQL code, whichever column it is.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    20

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    error converting varchar to numeric when saving after removing the automatic generate id from the insert command

  7. #7
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,148

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    can you show us you corrected code

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    Then you've got your columns mixed up. Are you using parameters? If not then you should fix that immediately. If you are, show us the code.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    20

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    code ttached as per ur request
    Attached Files Attached Files

  10. #10
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,148

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    You are not passing the values in the proper order,
    In the fields section the Prin_amount is in the second place but when you are passing the values, it is in the last place

    if should be something like this
    "Insert Into TableName (a,b,c,d) Values (Value_a, Value_b, Value_c, Value_d)"
    but you have jumbled the values

    And the most important you have ignored the previous advice by JMC
    You Should Consider Using Parameters

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    20

    Re: undiscclosed quotation mark after the character string')'.incorrect syntax near '

    it's working now.
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width