Private Sub InsertData()
Me.BikeTableAdapter.Fill(Me.ChanonDBDataSet.bike)
Dim sql As String
sql = "INSERT INTO bike (bike_id, band, model, cc, series, color, number, price)
VALUES (@bike_id, @band, @model, @cc, @series, @color, @number, @price)"
CheckDB()
Dim cmdadd As New OleDbCommand(sql, connection)
With cmdadd
.Parameters.AddWithValue("@bike_id", TextID.Text)
.Parameters.AddWithValue("@band", Comboband.Text)
.Parameters.AddWithValue("@model", ComboModel.Text)
.Parameters.AddWithValue("@cc", Textcc.Text)
.Parameters.AddWithValue("@series", TextSeries.Text)
.Parameters.AddWithValue("@color", TextColor.Text)
.Parameters.AddWithValue("@number", TextNumber.Text)
.Parameters.AddWithValue("@price", TextPrice.Text)
Dim r As Integer = .ExecuteNonQuery()
If r = -1 Then
MessageBox.Show("เกิดข้อผิดพลาด ไม่สามารถเพิ่มข้อมูลได้")
Else
MessageBox.Show("บันทึกข้อมูลแล้ว")
BindingData()
End If
End With
End Sub
Private Sub InsertData()
Dim sql As String
sql = "INSERT INTO bike (bike_id, band, model, cc, series, color, b_number, price)
VALUES (@bike_id, @band, @model, @cc, @series, @color, @b_number, @price)"
CheckDB()
Dim cmdadd As New OleDbCommand(sql, connection)
With cmdadd
.Parameters.AddWithValue("@bike_id", TextID.Text)
.Parameters.AddWithValue("@band", Comboband.Text)
.Parameters.AddWithValue("@model", ComboModel.Text)
.Parameters.AddWithValue("@cc", Textcc.Text)
.Parameters.AddWithValue("@series", TextSeries.Text)
.Parameters.AddWithValue("@color", TextColor.Text)
.Parameters.AddWithValue("@b_number", TextNumber.Text)
.Parameters.AddWithValue("@price", TextPrice.Text)
Dim r As Integer = .ExecuteNonQuery()
If r = -1 Then
MessageBox.Show("เกิดข้อผิดพลาด ไม่สามารถเพิ่มข้อมูลได้")
Else
MessageBox.Show("บันทึกข้อมูลแล้ว")
BindingData()
End If
End With
End Sub
Imports System.Data
Imports System.Data.OleDb
Module Module1
Public conStr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Admins\Documents\Visual Studio 2015\Projects\ChanonBike\ChanonBike\ChanonDB.mdb;" & "Persist Security Info=True;"
Public connection As New OleDbConnection(conStr)
Public command As OleDbCommand
Public dataSt As DataSet
Public adapter As OleDb.OleDbDataAdapter
Public bindingSrc As BindingSource
Public sql As String
Sub CheckDB()
With connection
If .State = ConnectionState.Open Then .Close()
.Open()
End With
End Sub
End Module