我正在使用Microsoft Visual Studio 2010 Express,並且正在嘗試使用VB.NET製作註冊表單。這是我的代碼到目前爲止:INSERT INTO語句獲取語法錯誤
Private Sub insrt()
If picStr = vbNullString Then
'save the current image default (noimage)
picImage.Image.Save(".png", Imaging.ImageFormat.Png)
'reload current " Noimage" to a binary
picStr = Application.StartupPath + (".\noimage.png")
End If
'set image object to value
IMG = (Nothing)
IMG = Image.FromFile(picStr)
'fill mystream into image binary
MyStream = New MemoryStream
IMG.Save(MyStream, Imaging.ImageFormat.Png)
Dim gen As String = String.Empty
If rbtnMale.Checked = True Then
gen = "Male"
ElseIf rbntFemale.Checked = True Then
gen = "Female"
End If
Dim dob As String = cboDay.Text & "/" & cboMonth.Text & "/" & txtYr.Text
Dim con As New OleDbConnection(cnSettings)
con.Open()
Try
If txtID.Text = "" Then
MsgBox("Please Enter year enrolled and Generate ID for this Student")
Exit Sub
Else
Dim cmd As New OleDbCommand
cmd.Connection = con
cmd.CommandText = "INSERT into tbEnroll(StudentID,Firstname,Lastname,Gender,DOB,Hometown,Region,Sess,Batch,Class,GFirstname,GLastname,GTel,GEmail,GResidence,DateEnroll,Picture) values ('" & txtID.Text & "','" & txtFN.Text & "','" & txtLN.Text & "','" & gen & "','" & dob & "','" & txtHomeTWN.Text & "','" & cboRegion.Text & "','" & cboSession.Text & "','" & txtBatch.Text & "','" & cboClass.Text & "','" & txtGfirst.Text & "','" & txtLastnm.Text & "','" & txtTel.Text & "','" & txtEmail.Text & "','" & txtRes.Text & "','" & DateTimePicker1.Text & "', @img ,)"
cmd.Parameters.AddWithValue("@img", OleDbType.VarBinary).Value = MyStream.GetBuffer
cmd.ExecuteNonQuery()
cmd.Dispose()
MyStream.Dispose()
MyStream = Nothing
MsgBox("Enrollment Done successfully", , "Enrollment")
cleartxt()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
有什麼可以解決這個問題?
*一個*問題是'Class'是一個保留字,另一個沒有使用SQL param因爲在那個糟糕的SQL湯中可能會有太多或太少的滴答。另一種是通過將所有內容作爲字符串傳遞而導致無意的數據類型轉換。 – Plutonix