Question SQL Query problem

salmanfalcon

New member
Joined
Jun 18, 2010
Messages
1
Programming Experience
Beginner
hi everyone,
These are my codes, the queries are teasing me too much, i am loosing my will, please help me, small query is working & but long is not working.
The error comes when i press SaveBtn is: Sql query syntax error INSERTINTO

' codes begin

Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
If mod_SerialNo = 0 Then ' code for new record
If MsgBox("Are you sure? ", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then
If InsertRecord() = 1 Then
MsgBox("Record saved successfully")
ClearFields()
' DistinctClass()
mod_SerialNo = 0
Else
MsgBox("Information Error. Does Not Save")
End If
End If
Else ' code for edit/update
If MsgBox("Do you want to update? ", MsgBoxStyle.YesNo, "Confirm") = MsgBoxResult.Yes Then
If MsgBox("Recrod Updated Successfully") Then
ClearFields()
' DistinctClass()
mod_SerialNo = 0
Else
MsgBox("Information Error. Does Not Update")
End If
End If
End If
End Sub
Public Function InsertRecord() As Integer
Dim str As String
Dim Yes, SerialNo As Integer
SerialNo = getNewSerialNo()
'this query is not working, i don't know why
str = " INSERT into

mytable(serialno,name,phone,mobile,date,duedate,frameamount,glassamount,totalamount,remarks,rpn,rsph,rcyl,raxis,npn,nsp

h,ncyl,naxis) VALUES('" & SerialNo & "','" & Trim(NameTxt_ip.Text) & "','" & Trim(PhoneTxt_ip.Text) & "','" &

Trim(MobileTxt_ip.Text) & "','" & Format(Date_ip.Value, "MM-dd-yyyy") & "','" & Format(DueDate_ip.Value, "MM-dd-yyyy") &

"','" & Trim(FrameAmount_ip.Text) & "','" & Trim(GlassAmount_ip.Text) & "','" & Trim(TotalAmount_ip.Text) & "','" &

Trim(RemarksTxt_ip.Text) & "','" & Trim(RightPN_ip.Text) & "','" & Trim(RightSph_ip.Text) & "','" & Trim(RightCyl_ip.Text) & "','"

& Trim(RightAxis_ip.Text) & "','" & Trim(LeftPN_ip.Text) & "','" & Trim(LeftSph_ip.Text) & "','" & Trim(LeftCyl_ip.Text) & "','" &

Trim(LeftAxis_ip.Text) & "')"
'this query is working
'str = " INSERT into mytable(name,phone,mobile) VALUES('" & Trim(NameTxt_ip.Text) & "','" & Trim(PhoneTxt_ip.Text) &

"','" & Trim(MobileTxt_ip.Text) & "')"
Try
con.Open()
Dim com1 As New OleDb.OleDbCommand(str, con)
Yes = com1.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MsgBox(ex.ToString)
con.Close()
Yes = 0
End Try
Return (Yes)
End Function

Project deadline is over, but i could not complete the project.
i don't know what is the problem in long query?
HELP ME PLEASE!
I hope any VB.NET angel will help me.
thanks, bye...
 
:eek:

You REALLY need to learn about PQs (parameterised queries) - please see the link in my signature.

Oh, and please use CODE tags when posting code on this forum :D

My guess is that the problem lies with your SerialNo field - what's the field type? If it's numeric, why are you encapsulating it in quotes? If you were using PQs, most of your problems would probably go away :)
 
Take a read of the DW2 link in my signature, section "Creating a Simple Data App" - it will take you through a tutorial of how to do data access in a modern way. At the end of it wo'll be able to write queries quikly and easily, and the code will be a lot more readable, secure and hgher performance than what you have here
 
Back
Top