Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_ok.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Projects\login_test\login_test\bin\database\user_login.mdb;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
If username.Text = "" Or password_txt.Text = "" Then
MessageBox.Show("ใส่ข้อมูล", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
ReadMyData(Cnnstring)
End If
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
On Error GoTo 0
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
End With
SqlSelect = "select * from user_db Where idname = '" & username.Text & "' and Password = '" & password_txt.Text & "'"
Dim OleCommand As New OleDbCommand(SqlSelect, Cnn)
OleReader = OleCommand.ExecuteReader
OleReader.Read()
str_idname = OleReader.Item("idname")
str_password = OleReader.Item("password")
Cnn.Close()
If username.Text = str_idname And password_txt.Text = str_password Then
goods.Show()
username.Text = ""
password_txt.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
เหมือนกับว่า if else จะไม่ทำงานอย่างนั้นล่ะ ใครช่วยได้บอกทีครับ มือใหม่ๆ
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_ok.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Projects\login_test\login_test\bin\database\user_login.mdb;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
If username.Text = "" Or password_txt.Text = "" Then
MessageBox.Show("ใส่ข้อมูล", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
ReadMyData(Cnnstring)
End If
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
On Error GoTo 0
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
End With
SqlSelect = "select * from user_db Where idname = '" & username.Text & "' and Password = '" & password_txt.Text & "'"
Dim OleCommand As New OleDbCommand(SqlSelect, Cnn)
OleReader = OleCommand.ExecuteReader
OleReader.Read()
str_idname = OleReader.Item("idname")
str_password = OleReader.Item("password")
Cnn.Close()
If username.Text = str_idname And password_txt.Text = str_password Then
goods.Show()
username.Text = ""
password_txt.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_ok.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Projects\login_test\login_test\bin\database\user_login.mdb;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
If username.Text = "" Or password_txt.Text = "" Then
MessageBox.Show("ใส่ข้อมูล", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
ReadMyData(Cnnstring)
End If
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
On Error GoTo 0
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
End With
SqlSelect = "select * from user_db Where idname = '" & username.Text & "' and Password = '" & password_txt.Text & "'"
Dim OleCommand As New OleDbCommand(SqlSelect, Cnn)
OleReader = OleCommand.ExecuteReader
OleReader.Read()
If Not DataRDA.HasRows Then
str_idname = OleReader.Item("idname")
str_password = OleReader.Item("password")
Else
MessageBox.Show("User name or password Incorrec")
End If
Cnn.Close()
If username.Text = str_idname And password_txt.Text = str_password Then
goods.Show()
username.Text = ""
password_txt.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_ok.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Projects\login_test\login_test\bin\database\user_login.mdb;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
If username.Text = "" Or password_txt.Text = "" Then
MessageBox.Show("ใส่ข้อมูล", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
ReadMyData(Cnnstring)
End If
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
On Error GoTo 0
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
End With
SqlSelect = "select * from user_db Where idname = '" & username.Text & "' and Password = '" & password_txt.Text & "'"
Dim OleCommand As New OleDbCommand(SqlSelect, Cnn)
OleReader = OleCommand.ExecuteReader
OleReader.Read()
If Not OleReader.HasRows Then
str_idname = OleReader.Item("idname")
str_password = OleReader.Item("password")
Else
MessageBox.Show("User name or password Incorrec")
End If
Cnn.Close()
If username.Text = str_idname And password_txt.Text = str_password Then
goods.Show()
username.Text = ""
password_txt.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub