مشاركة مني لكم فهذا كلاس لفورم باداة كومبوبوكس باسم username يتعبا من عمود باسم un ومربع نص باسم password مربوط بعمود باسم ps
التصريحات العامة:
اجراء تعبئة الكومبوبكس باسماء المستخدمين:
ضمن حدث تحميل الفورم
دالة التحقق من البيانات
وضمن زر امر الدخول
والتالي كامل الكلاس
طبعا مسالة التحقق من هل الاتصال مفتوح ام لا مهمة حتى نضمن ان الخطا لا يتعلق بحالة الاتصال
التصريحات العامة:
كود :
Dim str As String = "provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\db.accdb"
Dim con As New OleDb.OleDbConnection(str)
Dim sql As String = String.Empty
Dim ds As DataSet
Dim da As OleDb.OleDbDataAdapterاجراء تعبئة الكومبوبكس باسماء المستخدمين:
كود :
Private Sub gusers()
sql = "select un from tb"
ds = New DataSet
da = New OleDb.OleDbDataAdapter(sql, con)
usernam.Items.Clear()
ds.Clear()
da.Fill(ds, "tb")
usernam.DataSource = ds.Tables("tb")
usernam.DisplayMember = "un"
End Subضمن حدث تحميل الفورم
كود :
gusers()
If con.State = ConnectionState.Open Then
con.Close()
End Ifدالة التحقق من البيانات
كود :
Private Function isfound(ByVal un As String, ByVal ps As String) As Boolean
Dim cm As New OleDb.OleDbCommand("", con)
cm.CommandText = "select count(tid) from tb where un='" & un & "' and ps='" & ps & "'"
If con.State = ConnectionState.Closed Then
con.Open()
End If
If cm.ExecuteScalar > 0 Then
Return True
If con.State = ConnectionState.Open Then
con.Close()
End If
Else
Return False
If con.State = ConnectionState.Open Then
con.Close()
End If
End If
If con.State = ConnectionState.Open Then
con.Close()
End If
End Functionكود :
If isfound(usernam.Text, password.Text) = False Then
MsgBox("Not Found", MsgBoxStyle.Critical, "ERROR")
Else
MsgBox("Welcom .. here", MsgBoxStyle.Information, "welcom")
End If
If con.State = ConnectionState.Open Then
con.Close()
End Ifوالتالي كامل الكلاس
كود :
Public Class Form1
Dim str As String = "provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\db.accdb"
Dim con As New OleDb.OleDbConnection(str)
Dim sql As String = String.Empty
Dim ds As DataSet
Dim da As OleDb.OleDbDataAdapter
Private Sub gusers()
sql = "select un from tb"
ds = New DataSet
da = New OleDb.OleDbDataAdapter(sql, con)
usernam.Items.Clear()
ds.Clear()
da.Fill(ds, "tb")
usernam.DataSource = ds.Tables("tb")
usernam.DisplayMember = "un"
End Sub
Private Function isfound(ByVal un As String, ByVal ps As String) As Boolean
Dim cm As New OleDb.OleDbCommand("", con)
cm.CommandText = "select count(tid) from tb where un='" & un & "' and ps='" & ps & "'"
If con.State = ConnectionState.Closed Then
con.Open()
End If
If cm.ExecuteScalar > 0 Then
Return True
If con.State = ConnectionState.Open Then
con.Close()
End If
Else
Return False
If con.State = ConnectionState.Open Then
con.Close()
End If
End If
If con.State = ConnectionState.Open Then
con.Close()
End If
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
gusers()
If con.State = ConnectionState.Open Then
con.Close()
End If
End Sub
Private Sub btn_login_Click(sender As Object, e As EventArgs) Handles btn_login.Click
If isfound(usernam.Text, password.Text) = False Then
MsgBox("Not Found", MsgBoxStyle.Critical, "ERROR")
Else
MsgBox("Welcom .. here", MsgBoxStyle.Information, "welcom")
End If
If con.State = ConnectionState.Open Then
con.Close()
End If
End Sub
End Classطبعا مسالة التحقق من هل الاتصال مفتوح ام لا مهمة حتى نضمن ان الخطا لا يتعلق بحالة الاتصال
اللهم إني أعوذ بك من غلبة الدين وغلبة العدو، اللهم إني أعوذ بك من جهد البلاء ومن درك الشقاء ومن سوء القضاء ومن شماتة الأعداء
اللهم اغفر لي خطيئتي وجهلي، وإسرافي في أمري وما أنت أعلم به مني، اللهم اغفر لي ما قدمت وما أخرت، وما أسررت وما أعلنت وما أنت أعلم به مني، أنت المقدم وأنت المؤخر وأنت على كل شيء قدير

