[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
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.
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
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.
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