منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : تصحيح الكود لو سمحتم
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم

ما الخطأ في الكود لو سمحتم ؟


كود :
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
الرجاء المساعدة العاجلة
ما هي حقول قاعدة البيانات ؟
وما هي lblerror.Show() ؟
قمت برفعها لك لتراها جيدا

اخبرني اين الخطأ لاني رأيت فيديوا لنفس الطريقة وشغالة عنده لما جيت اطبقها حرفيا لم تعمل والسورس حقه ايضا لم يعمل ولكن في الفيديوا شغال
اولا : غير اسم الجدول user  إلى users
ثانيا الكود كالتالي بعد تصحيح بعض النقاط


PHP كود :
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
(ByVal sender As ObjectByVal e As EventArgsHandles btnExit.Click
        Application
.Exit()
 
   End Sub

    Private Sub btnLogin_Click
(ByVal sender As ObjectByVal e As EventArgsHandles btnLogin.Click
        If txtUserName
.Text.Length <= Or txtPassword.Text.Length <= 0 Then
            MessageBox
.Show("Please Enter UserName or Password""Error"MessageBoxButtons.OKMessageBoxIcon.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 [Users] 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(userid) from users where username = '" & 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 username = '" & txtUserName.Text & "'"
            RD = cmd.ExecuteReader
            RD.Read()
            If RD.Item("username") = txtUserName.Text And RD.Item("password") = 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(ByVal sender As Object, ByVal 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 
عندك خطأ بسيط ويكون


كود :
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(ByVal sender As Object, ByVal e As EventArgs) Handles btnExit.Click
       Application.Exit()
   End Sub

   Private Sub btnLogin_Click(ByVal sender As Object, ByVal 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 [Users] 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
             
               txtUserName.Text = ""
               txtPassword.Text = ""
               txtUserName.SelectAll()
           
           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(userid) from users where username = '" & 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 username = '" & txtUserName.Text & "'"
           RD = cmd.ExecuteReader
           RD.Read()
           If RD.Item("username") = txtUserName.Text And RD.Item("password") = 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(ByVal sender As Object, ByVal 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