Imports System.Data
Imports System.Data.OleDb
Public Class Form3
Inherits System.Windows.Forms.Form
Dim mycon As OleDbConnection
Dim myAdapter As OleDbDataAdapter
Dim dataset As New DataSet
Dim mycmd As OleDbCommand
Dim mycmd1 As OleDbCommand
Dim mycmd2 As OleDbCommand
Dim mycmd3 As OleDbCommand
Dim myreader As OleDbDataReader
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MemberDataSet.member' table. You can move, or remove it, as needed.
Me.MemberTableAdapter.Fill(Me.MemberDataSet.member)
mycon = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HP-DN\Desktop\Project\Project\Member.accdb")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" And TextBox2.Text = "" Then
MessageBox.Show("กรุณาใส่ข้อมูลให้ครบ", "ผิดพลาด")
Exit Sub
End If
mycon.Open()
mycmd1 = New OleDbCommand("SELECT COUNT(*) FROM member;", mycon)
If mycmd1.ExecuteScalar = 0 Then
mycon.Close()
mycmd = New OleDbCommand("Insert INTO member(username,password) values(TextBox1.Text,TextBox2.Text)", mycon)
mycmd.Parameters.AddWithValue("@username", TextBox1.Text)
mycmd.Parameters.AddWithValue("@password", TextBox2.Text)
mycon.Open()
mycmd.ExecuteNonQuery()
mycon.Close()
End If
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class
ช่วยแก้โค็ด บันทึกลง DB ไม่ได้
Imports System.Data.OleDb
Public Class Form3
Inherits System.Windows.Forms.Form
Dim mycon As OleDbConnection
Dim myAdapter As OleDbDataAdapter
Dim dataset As New DataSet
Dim mycmd As OleDbCommand
Dim mycmd1 As OleDbCommand
Dim mycmd2 As OleDbCommand
Dim mycmd3 As OleDbCommand
Dim myreader As OleDbDataReader
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MemberDataSet.member' table. You can move, or remove it, as needed.
Me.MemberTableAdapter.Fill(Me.MemberDataSet.member)
mycon = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HP-DN\Desktop\Project\Project\Member.accdb")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" And TextBox2.Text = "" Then
MessageBox.Show("กรุณาใส่ข้อมูลให้ครบ", "ผิดพลาด")
Exit Sub
End If
mycon.Open()
mycmd1 = New OleDbCommand("SELECT COUNT(*) FROM member;", mycon)
If mycmd1.ExecuteScalar = 0 Then
mycon.Close()
mycmd = New OleDbCommand("Insert INTO member(username,password) values(TextBox1.Text,TextBox2.Text)", mycon)
mycmd.Parameters.AddWithValue("@username", TextBox1.Text)
mycmd.Parameters.AddWithValue("@password", TextBox2.Text)
mycon.Open()
mycmd.ExecuteNonQuery()
mycon.Close()
End If
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class