SQL statement problem

adi_uk

Member
Joined
Mar 22, 2006
Messages
12
Programming Experience
1-3
Im having a problem with sql statements again. I keep getting an error saying my syntax is invalid, although i cant see where. Have i done it totally wrong?

MANAGE TO SOLVE IT WITH THE FOLLOWING CODE

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] add()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sa [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]Title = TextBox7.Text
Artist = TextBox8.Text
Tracks = TextBox9.Text
RunningTime = TextBox10.Text
ID = textbox11.text
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myConn [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbConnection(myConnectionString)
myConn.Open()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myComm [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbCommand("INSERT INTO CDList (Title,Artist,Tracks,RunningTime) VALUES ('" & Title & "','" & Artist & "'," & [/SIZE][SIZE=2][COLOR=#0000ff]CStr[/COLOR][/SIZE][SIZE=2](Tracks) & "," & [/SIZE][SIZE=2][COLOR=#0000ff]CStr[/COLOR][/SIZE][SIZE=2](RunningTime) & ")", myConn)
sa = myComm.ExecuteNonQuery
Response.Write("CD" & Title & " updated")
myConn.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
Response.Write("Update Error " & " " & ex.Message)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][/COLOR][/SIZE]
 
Last edited:
As i know String must put ', try below code if stil have problem tell me~

Dim myComm AsNew OleDbCommand("INSERT INTO CDList (Title,Artist,Tracks,RunningTime) VALUES ('" & Title & "','" & Artist & "','" & CStr(Tracks) & "','" & CStr(RunningTime) & "')", myConn)

 
Back
Top