29-08-17, 12:55 PM
السلام عليكم
ما الخطأ في الكود لو سمحتم ؟
الرجاء المساعدة العاجلة
ما الخطأ في الكود لو سمحتم ؟
كود :
Imports System.Data.OleDb
Public Class frmUser
Dim cn As New OleDbConnection
Dim mytable As DataTable
Dim da As New OleDbDataAdapter
Dim cmd As New OleDb.OleDbCommand
Dim RD As OleDbDataReader
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Application.Exit()
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
If txtUserName.Text.Length <= 0 Or txtPassword.Text.Length <= 0 Then
MessageBox.Show("Please Enter UserName or Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb;Persist Security Info=False;")
cn.Open()
cmd = New OleDbCommand("select * from [User] where [UserName]= '" & txtUserName.Text.ToString() & "' and [Password]='" + txtPassword.Text.ToString() + "'", cn)
RD = cmd.ExecuteReader()
mytable = New DataTable()
mytable.Load(RD)
cn.Close()
If mytable.Rows.Count = 0 Then
lblerror.Show()
txtUserName.Text = ""
txtPassword.Text = ""
txtUserName.SelectAll()
Else
Dim F1 As New Form1
F1.Show()
Me.Hide()
End If
If txtUserName.Text = vbNullString Or txtPassword.Text = vbNullString Then
MsgBox("لم تقم بإدخال أسم المستخدم أو كلمة المرور ")
Exit Sub
End If
If cn.State = ConnectionState.Open Then cn.Close()
cn.Open()
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECt count (id) from users where user = '" & txtUserName.Text & "'"
If cmd.ExecuteScalar.ToString = 0 Then
MsgBox("أسم المستخدم أو كلمة المرور خطأ !")
Exit Sub
End If
cn.Close()
If cn.State = ConnectionState.Open Then cn.Close()
cn.Open()
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROm users where user = '" & txtUserName.Text & "'"
RD = cmd.ExecuteReader
RD.Read()
If RD.Item("user") = txtUserName.Text And RD.Item("pass") = txtPassword.Text Then
Form1.Show()
Me.Hide()
Else
MsgBox("أسم المستخدم أو كلمة المرور غير صحيحة ")
Exit Sub
End If
Form1.Button1.Visible = False
Form1.Button2.Visible = False
Form1.Button3.Visible = False
Form1.Button4.Visible = False
Form1.Button5.Visible = False
Form1.Button6.Visible = False
Form1.Button7.Visible = False
Form1.Button8.Visible = False
If RD.Item("c1") = True Then
Form1.Button1.Visible = True
End If
If RD.Item("c2") = True Then
Form1.Button2.Visible = True
End If
If RD.Item("c3") = True Then
Form1.Button3.Visible = True
End If
If RD.Item("c4") = True Then
Form1.Button4.Visible = True
End If
If RD.Item("c5") = True Then
Form1.Button5.Visible = True
End If
If RD.Item("c6") = True Then
Form1.Button6.Visible = True
End If
If RD.Item("c7") = True Then
Form1.Button7.Visible = True
End If
If RD.Item("c8") = True Then
Form1.Button8.Visible = True
End If
End If
End Sub
Private Sub frmUser_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb;Persist Security Info=False;")
End Sub
End Class