Imports System.Data.OleDb
Imports System.Data
Public Class Form2
Public conn As New OleDbConnection
Public Sub connectData() Handles MyBase.Load
Dim P As String
'TODO: This line of code loads data into the 'DataSet.Age' table. You can move, or remove it, as needed.
Me.AgeTableAdapter.Fill(Me.DataSet.Age)
'TODO: This line of code loads data into the 'DataSet.Sex' table. You can move, or remove it, as needed.
Me.SexTableAdapter.Fill(Me.DataSet.Sex)
'TODO: This line of code loads data into the 'DataSet.AddP' table. You can move, or remove it, as needed.
Me.AddPTableAdapter.Fill(Me.DataSet.AddP)
'TODO: This line of code loads data into the 'DataSet.Product' table. You can move, or remove it, as needed.
Me.ProductTableAdapter.Fill(Me.DataSet.Product)
If conn.State = ConnectionState.Open Then conn.Close()
P = "Provider=Microsoft.Jet.OLEDB.4.0;"
P = P + "Data Source=d:\TPro\data.mdb;"
P += "User Id=admin;Password=;"
conn.ConnectionString = P
conn.Open()
End Sub
Public Function ExecuteSQL(ByVal prmSQL As String) As Boolean
connectData()
Dim addCom As New OleDbCommand
With addCom
.CommandType = CommandType.Text
.CommandText = prmSQL
.Connection = conn
.ExecuteNonQuery()
End With
ExecuteSQL = True
End Function
Private Sub Formload() Handles MyBase.Load
connectData()
End Sub
Private Sub AddData() Handles btnAdd.Click
Dim S As String
S = "INSERT INTO Addp (Code,Pname,Sex,Age,[Price])VALUES("
S += "'" & txtcode.Text & "',"
S += "'" & cmbName.Text & "'"
S += "'" & cmbSex.Text & "'"
S += "'" & cmbAge.Text & "'"
S += "'" & txtPrice.Text & "'"
S += ")"
ExecuteSQL(S)
MessageBox.Show("บันทึกเรียบร้อย", "ยืนยัน")
End Sub