Imports System.Data.OleDb
Imports System.Data
Public Class Form1
Public conn As New OleDbConnection
Public Sub connectData() Handles MyBase.Load
Dim s As String
If conn.State = ConnectionState.Open Then conn.Close()
s = "Provider=Microsoft.ACE.OLEDB.12.0;"
s = s + "Data Source=C:\Database.accdb;"
s += "User Id = Admin;Password=;"
conn.ConnectionString = s
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 DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsell_date.ValueChanged
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connectData()
MsgBox("เชื่อมต่อฐานข้อมูลสำเร็จ")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'เพิ่มข้อมูลลงในตาราง Selling'
Dim sql As String = "INSERT INTO selling(sell_no) VALUES " & "(@sell_no)"
Dim cmd1 As New OleDbCommand(sql, conn)
cmd1.Parameters.AddWithValue("@sell_no", txtsell_no.Text)
cmd1.ExecuteNonQuery()
'เพิ่มข้อมูลลงในตาราง Employee'
Dim sql2 As String = "INSERT INTO employee(emp_id) VALUES " & "(@emp_id)"
Dim cmd2 As New OleDbCommand(sql2, conn)
cmd2.Parameters.AddWithValue("@emp_id", txtemp_id.Text)
cmd2.ExecuteNonQuery()
'Dim sql As String =
'sql = "INSERT INTO selling(sell_no, sell_date)VALUES("
'sql += "'" & txtsell_no.Text & "',"
'sql += "'" & txtsell_date.Text & "'"
'sql += ")"
'sql = "INSERT INTO employee(emp_id)VALUES("
'sql += "'" & txtemp_id.Text & "'"
' sql += ")"
'sql = "INSERT INTO product(pro_id, pro_price, pro_name, pro_amount)VALUES("
'sql += "'" & txtpro_id.Text & "',"
'sql += "'" & txtpro_price.Text & "',"
'sql += "'" & txtpro_name.Text & "',"
'sql += "'" & txtpro_amount.Text & "'"
'sql += ")"
'ExecuteSQL(sql)
MsgBox("บันทึกข้อมูลสำเร็จ")
End Sub
Private Sub txtsell_no_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsell_no.TextChanged
End Sub
End Class
Tag : .NET, Ms Access, VBScript, VS 2008 (.NET 3.x), Windows