sql = "insert into reservation (train_no,trainame,from,to,name1,age) values(" &
Val(lbl3.Caption) & ",' " & lbl4.Caption & "','" & findtrain.srce.Text &
"','" & findtrain.dstn.Text & "','" & Form3.Text1.Text & "'," &
Val(Form3.Text3.Text) & ")"
这里的语法错误是什么?
答案 0 :(得分:0)
为什么不在ADO中使用参数?它会更容易调试。
Public Function Insert(ByVal Values As String) As Integer
Dim sCon As String = ConnectionString()
Dim sel As String
sel = "INSERT INTO " & NombreTabla & _
"(Columns) " & _
"VALUES " & _
"(@Params) " & _
"SELECT @@Identity"
Using con As New SqlConnection(sCon)
Dim cmd As New SqlCommand(sel, con)
cmd.Parameters.AddWithValue("@Params", Values)
con.Open()
Dim t As Integer = CInt(cmd.ExecuteScalar())
con.Close()
Return t
End Using
End Function