 |
|
help-VB ทำหน้า login เชื่อมต่อกับ access พิมรหัสมั่วไม่ผ่าน อ่านด้านใน |
|
 |
|
|
 |
 |
|
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2009-09-02 14:05:47 |
By :
saesee1125 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันก่อนหน้าพอดีผมก๊อบโค๊ดมาว่างเพื่อดูให้ง่ายขึ้นครับ
อันนี้ผมแก้แล้วน่าจะผ่านแล้วนะครับ
ที่ผิดตอนแรกคือไม่มีการ ตรวจสอบว่ามีค่าในฐานข้อมูลหรือเปล่านะครับ
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2009-09-02 14:14:08 |
By :
saesee1125 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาใหม่ครับ อันนั้นลืมแก้นิดหนึ่ง
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2009-09-02 14:17:05 |
By :
saesee1125 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้ครับ ยังเหมือนเดิม
แถมเมื่อพิมรหัสผ่นและไอดีถูก กลับเข้าไม่ได้ด้วย
|
 |
 |
 |
 |
Date :
2009-09-02 17:49:00 |
By :
phoenix69 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|