Dim Cnn As New OleDbConnection(Cnnstring)
Dim Cnnstring As String
Dim SqlSelect As String
Dim OleReader As OleDbDataReader
Dim UserIDA As String
Dim PassIDA As String
Code (VB.NET)
Private Sub cmdlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlogin.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database/data_app.mdb;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
If usertxt.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 tbuserlogin Where Username = " & "'" & usertxt.Text & "'"
Dim OleCommand As New OleDbCommand(SqlSelect, Cnn)
OleReader = OleCommand.ExecuteReader
OleReader.Read()
UserIDA = OleReader.Item("username")
PassIDA = OleReader.Item("password")
Cnn.Close()
If usertxt.Text = UserIDA And passtxt.Text = PassIDA Then
Form2.Show()
usertxt.Text = ""
passtxt.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Dim Sql_Log As String = "select * from t_user where user_id = '" & TxtId.Text & "'"
Da_AdMin.MissingSchemaAction = MissingSchemaAction.AddWithKey
Da_AdMin.SelectCommand = New OleDbCommand(Sql_Log, Con)
Try
Da_AdMin.Fill(Ds_AdMin, "log")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim Dr As DataRow
If Ds_AdMin.Tables("log").Rows.Count = 0 Then
MessageBox.Show("ไม่มีรหัสสมาชิกรหัสนี้ " & TxtId.Text, "ไม่มีข้อมูล", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dr = Ds_AdMin.Tables("log").Rows(0)
Dim Pass As String = Dr("user_password").ToString
If TxtPassWord.Text <> Pass Then
MessageBox.Show("รหัสผ่านไม่ถูกต้อง", "รหัสไม่ถูกต้อง", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
End If
End If
Ds_AdMin.Tables("log").Clear()
Imports System.Data.OleDb
Imports System.Data
Partial Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Onload Event
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim objConn As OleDbConnection
Dim dtAdapter As OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("database/mydatabase.mdb") & ";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM user WHERE Username = '" & Me.txtUsername.Text & "'" & _
" AND Password = '" & Me.txtPassword.Text & "' "
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
If dt.Rows.Count <= 0 Then
Me.lblMsg.Text = "Invalid Username & Password"
Else
Response.Redirect("Wecome.aspx")
End If
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If TextBox1.Text <> "" Or TextBox2.Text <> "" Then
Dim cm As New OleDbCommand("select user,pass from login where user='" & TextBox1.Text & "' and pass='" & TextBox2.Text & "'", con)
Dim Rd As OleDbDataReader
Dim userlogin, passlogin As String
con.Open()
Rd = cm.ExecuteReader
Rd.Read()
userlogin = Rd.Item("user")
passlogin = Rd.Item("pass")
con.Close()
If TextBox1.Text = userlogin And TextBox2.Text = passlogin Then
MsgBox("ยินดีต้อนรับคุณ " & userlogin & " เข้าสู่ระบบครับ")
End If
End If
Catch ex As Exception
MsgBox("คุณไม่มีสิทธิ์เข้าใช้ระบบนะครับ T-T")
Exit Sub
End Try
End Sub
End Class
ใส่ตรงบน Public Class
Code (VB.NET)
view sourceprint?1.Imports system.Data
2.Imports System.Data.OleDb
ใส่ตรงล่าง Public Class
Code (VB.NET)
view sourceprint?1.Dim Cnn As New OleDbConnection(Cnnstring)
2.Dim Cnnstring As String
3.Dim SqlSelect As String
4.Dim OleReader As OleDbDataReader
5.Dim UserIDA As String
6.Dim PassIDA As String
ใส่ตรงไหนครับ ผมใช้ VB.net 2008
Date :
2011-01-26 06:55:10
By :
bank
No. 39
Guest
ท่านที่ติดเหมือน ท่าน crackza
ลองเติม While เข้าไปดูนะค่ะ
ใส่ตรงบน Public Class
Code (VB.NET)
view sourceprint?1.Imports system.Data
2.Imports System.Data.OleDb
ใส่ตรงล่าง Public Class
Code (VB.NET)
view sourceprint?1.Dim Cnn As New OleDbConnection(Cnnstring)
2.Dim Cnnstring As String
3.Dim SqlSelect As String
4.Dim OleReader As OleDbDataReader
5.Dim UserIDA As String
6.Dim PassIDA As String
Code (VB.NET) Code (VB.NET)
Private Sub cmdlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlogin.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database/data_app.mdb;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
If usertxt.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 tbuserlogin Where Username = " & "'" & usertxt.Text & "'"
Dim OleCommand As New OleDbCommand(SqlSelect, Cnn)
OleReader = OleCommand.ExecuteReader
OleReader.Read()
UserIDA = OleReader.Item("username")
PassIDA = OleReader.Item("password")
Cnn.Close()
If usertxt.Text = UserIDA And passtxt.Text = PassIDA Then
Form2.Show()
usertxt.Text = ""
passtxt.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
เสร็จ
Date : 2009-05-30 11:10:25 By : varittinan View : 14312 Reply : 41
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim UserName As String = UsernameTextBox.Text
Dim Pwd As String = PasswordTextBox.Text
ตารางในฐานข้อมูลSql ชื่อตารางadminมีการกำหนดสิทธิ์ เป็น admin และ user อยากให้มันขึ้นข้อความมแจ้งเตือนเวลาที่ใส่รหัสผิดจะต้องใส่ตรงไหนยังไง Run และ error
Dim Authen As String = ""
Dim sql As String
sql = "SELECT * FROM admin"
sql &= " WHERE (Username = @Username"
sql &= " AND Password = @Password)"
Dim Com As New SqlCommand(sql, conn)
Com.Parameters.Add("@Username", SqlDbType.VarChar).Value = UserName
Com.Parameters.Add("@Password", SqlDbType.VarChar).Value = Pwd
Dim dr As SqlDataReader = Com.ExecuteReader()
If dr.HasRows Then
dr.Read()
Authen = dr.GetString(dr.GetOrdinal("Authentication"))
If Authen = "admin" Then
Menu1.Show()
Menu1.exitprogram.Enabled = False
Me.Hide()
Else
Menu1.Show()
Menu1.menumaster.Enabled = False
Menu1.username.Enabled = False
Me.Hide()
End If
End If
End Sub