Dim cmd As New OleDbCommand
If Not con.State = ConnectionState.Open Then
'open connection if it is not yet open
con.Open()
End If
cmd.Connection = con
'add data to table
cmd.CommandText = "INSERT INTO tb_Out_Product(ID_Product,จำนวน,ชื่อคนยืม,ชื่อคนจ่าย,วันและเวลา)" & _
"VALUES (" & Me.ComboBox1.Text & ",'" & Me.TextBox3.Text & "','" & _
Me.TextBox4.Text & "','" & Me.TextBox5.Text & "','" & _
Me.DateTimePicker1.Text & "')"
cmd.ExecuteNonQuery()
'close connection
con.Close()
มันErrorตรง cmd.ExecuteNonQuery() ว่า
Code
Syntax error (missing operator) in query expression '202ส้ม'.
Public Overridable Overloads Function GetData() As ฐานข้อมูล1DataSet.Table1DataTable
Me.Adapter.SelectCommand = Me.CommandCollection(0)
Dim dataTable As ฐานข้อมูล1DataSet.Table1DataTable = New ฐานข้อมูล1DataSet.Table1DataTable()
Me.Adapter.Fill(dataTable)
Return dataTable
End Function
Public Overridable Overloads Function Delete(ByVal Original_ID As Integer, ByVal Original_type As Global.System.Nullable(Of Integer), ByVal Original_count As Global.System.Nullable(Of Integer)) As Integer
Me.Adapter.DeleteCommand.Parameters(0).Value = CType(Original_ID, Integer)
If (Original_type.HasValue = True) Then
Me.Adapter.DeleteCommand.Parameters(1).Value = CType(0, Object)
Me.Adapter.DeleteCommand.Parameters(2).Value = CType(Original_type.Value, Integer)
Else
Me.Adapter.DeleteCommand.Parameters(1).Value = CType(1, Object)
Me.Adapter.DeleteCommand.Parameters(2).Value = Global.System.DBNull.Value
End If
If (Original_count.HasValue = True) Then
Me.Adapter.DeleteCommand.Parameters(3).Value = CType(0, Object)
Me.Adapter.DeleteCommand.Parameters(4).Value = CType(Original_count.Value, Integer)
Else
Me.Adapter.DeleteCommand.Parameters(3).Value = CType(1, Object)
Me.Adapter.DeleteCommand.Parameters(4).Value = Global.System.DBNull.Value
End If
Dim previousConnectionState As Global.System.Data.ConnectionState = Me.Adapter.DeleteCommand.Connection.State
If ((Me.Adapter.DeleteCommand.Connection.State And Global.System.Data.ConnectionState.Open) _
<> Global.System.Data.ConnectionState.Open) Then
Me.Adapter.DeleteCommand.Connection.Open()
End If
Try
Dim returnValue As Integer = Me.Adapter.DeleteCommand.ExecuteNonQuery
Return returnValue
Finally
If (previousConnectionState = Global.System.Data.ConnectionState.Closed) Then
Me.Adapter.DeleteCommand.Connection.Close()
End If
End Try
End Function
Public Overridable Overloads Function Insert(ByVal type As Global.System.Nullable(Of Integer), ByVal count As Global.System.Nullable(Of Integer)) As Integer
If (type.HasValue = True) Then
Me.Adapter.InsertCommand.Parameters(0).Value = CType(type.Value, Integer)
Else
Me.Adapter.InsertCommand.Parameters(0).Value = Global.System.DBNull.Value
End If
If (count.HasValue = True) Then
Me.Adapter.InsertCommand.Parameters(1).Value = CType(count.Value, Integer)
Else
Me.Adapter.InsertCommand.Parameters(1).Value = Global.System.DBNull.Value
End If
Dim previousConnectionState As Global.System.Data.ConnectionState = Me.Adapter.InsertCommand.Connection.State
If ((Me.Adapter.InsertCommand.Connection.State And Global.System.Data.ConnectionState.Open) _
<> Global.System.Data.ConnectionState.Open) Then
Me.Adapter.InsertCommand.Connection.Open()
End If
Try
Dim returnValue As Integer = Me.Adapter.InsertCommand.ExecuteNonQuery
Return returnValue
Finally
If (previousConnectionState = Global.System.Data.ConnectionState.Closed) Then
Me.Adapter.InsertCommand.Connection.Close()
End If
End Try
End Function
Public Overridable Overloads Function Update(ByVal type As Global.System.Nullable(Of Integer), ByVal count As Global.System.Nullable(Of Integer), ByVal Original_ID As Integer, ByVal Original_type As Global.System.Nullable(Of Integer), ByVal Original_count As Global.System.Nullable(Of Integer)) As Integer
If (type.HasValue = True) Then
Me.Adapter.UpdateCommand.Parameters(0).Value = CType(type.Value, Integer)
Else
Me.Adapter.UpdateCommand.Parameters(0).Value = Global.System.DBNull.Value
End If
If (count.HasValue = True) Then
Me.Adapter.UpdateCommand.Parameters(1).Value = CType(count.Value, Integer)
Else
Me.Adapter.UpdateCommand.Parameters(1).Value = Global.System.DBNull.Value
End If
Me.Adapter.UpdateCommand.Parameters(2).Value = CType(Original_ID, Integer)
If (Original_type.HasValue = True) Then
Me.Adapter.UpdateCommand.Parameters(3).Value = CType(0, Object)
Me.Adapter.UpdateCommand.Parameters(4).Value = CType(Original_type.Value, Integer)
Else
Me.Adapter.UpdateCommand.Parameters(3).Value = CType(1, Object)
Me.Adapter.UpdateCommand.Parameters(4).Value = Global.System.DBNull.Value
End If
If (Original_count.HasValue = True) Then
Me.Adapter.UpdateCommand.Parameters(5).Value = CType(0, Object)
Me.Adapter.UpdateCommand.Parameters(6).Value = CType(Original_count.Value, Integer)
Else
Me.Adapter.UpdateCommand.Parameters(5).Value = CType(1, Object)
Me.Adapter.UpdateCommand.Parameters(6).Value = Global.System.DBNull.Value
End If
Dim previousConnectionState As Global.System.Data.ConnectionState = Me.Adapter.UpdateCommand.Connection.State
If ((Me.Adapter.UpdateCommand.Connection.State And Global.System.Data.ConnectionState.Open) _
<> Global.System.Data.ConnectionState.Open) Then
Me.Adapter.UpdateCommand.Connection.Open()
End If
Try
Dim returnValue As Integer = Me.Adapter.UpdateCommand.ExecuteNonQuery
Return returnValue
Finally
If (previousConnectionState = Global.System.Data.ConnectionState.Closed) Then
Me.Adapter.UpdateCommand.Connection.Close()
End If
End Try
End Function
ทำ Function ออกมาแบบนี้ก็ดูดีไปอีกแบบ
แต่ต้องออกตัวก่อนว่าข้อมูลข้างต้นมาจาก data wizard ล้วนๆผมไม่ได้คิดเอง 5555