hi there! can you please help me? this codes doesnt have any reponse from the database .. these codes is for case sensitivity of the usernametxtbox and if satisfied, the secretquestion textbox will automatically display the correct secret question. help me pls!

    Dim i As Integer
    Dim PassResult As String = ""

    Dim con As New OleDbConnection("Provider=Microsoft.ace.oledb.12.0;data source=C:\Users\user\Desktop\CBFMNHS Enrollment System\CBFMNHS Enrollment System\bin\Debug\Enrollment System.accdb")
    cmda = New OleDbCommand("Select * from EditAccount", con)
    con.Open()
    rid = cmda.ExecuteReader()
    rid.Read()
    While rid.Read()
        PassResult = rid.Item(1)
    End While
    i = String.Compare(TextBox1.Text, PassResult, False)
    If i = -1 Then
        MsgBox("wrong Input")
    ElseIf i = 0 Then
        If rid.Read = True Then

            TextBox4.Text = rid(5)
        End If

        End If

Post (or attach) a few records from the database and I'll have a look at it locally. If you can zip and attachthe entire database then I'll also have the schema.

Are you sure you have the connect connection string? Is this access database?
Please double check the correctness of connection string. Else I cannot suggest you now.

Can you also please explain (step by step) what you are trying to do? For example, it appears that in lines 9-11 you are reading through the entire table in order to retrieve a single value. I don't understand the reason for this. Perhaps if you explained your process in English rather than code it would be more clear.

hello every one .. i'm soryy for the late reply.

@mitja -- yes this from the data from the database..

@Jim -- here's the printscr of my database..
what i'm trying to do is to make sure that the username typed by the user.. is case sensitive from the the data on the database so that the corresponding secret question is revealed on TextBox4.Text.. i dont know how to declare the passresult that contains the data from the database that;s why it happens on the line 9-11.. i hope you can help me. :) thank you in advance..

I have done the same thing for username and password...check if it works for u

Why do u write the Item(1) code cant it be just written with reader name and quote brackets column name?
reader("DrName")

if ur case sensitivity code is creating error then check below

     Try
                    Dim myCommand As OleDbCommand
                    myCommand = New OleDbCommand("SELECT * FROM userlogin where UserName='" & txtUsername.Text & "' and Password='" + txtPassword.Text + "'", Connection)
                    Dim reader As OleDbDataReader = myCommand.ExecuteReader
                    If reader.Read = True Then
                        If String.Compare(txtUsername.Text, reader("UserName"), False) Or String.Compare(txtPassword.Text, reader("Password"), False) Then
                            MsgBox("Incorrect Credentials")
                            txtPassword.Text = ""
                            txtUsername.Text = ""
                            txtUsername.Focus()
                            ErrorProvider1.Clear()
                        Else
                            frmMain.lblWelcome.Text = "Welcome, " + reader("DrName")
                            frmMain.Show()
                            Me.Close()
                        End If
                    Else
                        MsgBox("Login Failed. Try Again")
                        txtPassword.Text = ""
                        txtUsername.Text = ""
                        txtUsername.Focus()
                        ErrorProvider1.Clear()
                    End If
                        reader.Close()
                Catch ex As Exception
                    MsgBox("Error Connecting to Database: " & ex.Message)
                End Try

there's an error

Object reference is not set to an instance an object..

and what is ErrorProvider1 ?

here's my code :

 con = New OleDbConnection("Provider= Microsoft.ACE.oledb.12.0; Data Source=|DataDirectory|\Enrollment System.accdb;Jet OLEDB:Database Password=jhedonghae;")
    con.Open()
    Try
        Dim myCommand As OleDbCommand
        myCommand = New OleDbCommand("SELECT * FROM Account where Username='" & TextBox1.Text & "' ", con)
        Dim reader As OleDbDataReader = myCommand.ExecuteReader
        If reader.Read = True Then
            If String.Compare(TextBox1.Text, reader("Username"), False) Then
                MsgBox("Incorrect Credentials")
                TextBox1.Clear()
                TextBox1.Focus()

            Else
                TextBox4.Text = rid(5)
                Me.Close()
            End If

            con.Close()
        End If
        reader.Close()
    Catch ex As Exception
        MsgBox("Error Connecting to Database: " & ex.Message)
    End Try

What about rid(5) at line #14? I think it should be reader(5).

PS: Never use hard-coded SQL strings. Use parameters.

    Dim Sql = "SELECT * FROM Account where Username=@Username"
    Dim UserName As String = String.Empty
    Using con As New OleDbConnection("your_conn_str")
        Using Command As New OleDbCommand(Sql, con)
            Command.Parameters.Add("@Username", OleDbType.VarChar, 40).Value = TextBox1.Text
            con.Open()
            Dim reader As OleDbDataReader = Command.ExecuteReader
            If reader.Read Then
                UserName = reader("Username")
            End If
            reader.Close()
            con.Close()
        End Using
    End Using

    If Not String.IsNullOrEmpty(UserName) Then
        'code
    Else
        'code
    End If

thank you poojavb and adatapost!

but adatapost what is @Username stands for? i tried your codes but it doesnt works.

Its a parameter name (you can see Adaposr is using parametreized query). This is simply what you define by your self (imagine it).
But you have to make sure both parameter names are equal, in query and when you define (passing a variable) to it.

I will make it more "readable":

"SELECT * FROM Account where Username = @parameter1"    
Command.Parameters.Add("@parameter1", OleDbType.VarChar, 40).Value = TextBox1.Text

i used it but but nothing happens happen again.. in this time i use it in Button..

 Dim Sql = "SELECT * FROM Account where Secret_Answer=@SA"
    Dim Secret_Answer As String = String.Empty
    Using con As New OleDbConnection("Provider= Microsoft.ACE.oledb.12.0; Data Source=|DataDirectory|\Enrollment System.accdb;Jet OLEDB:Database Password=jhedonghae;")
        Using Command As New OleDbCommand(Sql, con)
            Command.Parameters.Add("@SA", OleDbType.VarChar, 40).Value = TextBox2.Text
            con.Open()
            Dim reader As OleDbDataReader = Command.ExecuteReader
            If reader.Read Then
                Secret_Answer = reader("Secret_Answer")
            End If
            reader.Close()
            con.Close()
        End Using
    End Using
    If Not String.IsNullOrEmpty(Secret_Answer) Then
        'code
    Else
        'code
    End If

i used again adatapost codes.. but it does not works.. i insert the codes for Secret_Answer TextBox....

con = New OleDbConnection("Provider= Microsoft.ACE.oledb.12.0; Data Source=|DataDirectory|\Enrollment System.accdb;Jet OLEDB:Database Password=jhedonghae;")
    con.Open()
    Try
        Dim myCommand As OleDbCommand
        myCommand = New OleDbCommand("SELECT * FROM Account where Secret_Answer='" & TextBox2.Text & "' ", con)
        Dim reader As OleDbDataReader = myCommand.ExecuteReader
        If reader.Read = True Then
            If String.Compare(TextBox2.Text, reader("Secret_Answer"), False) Then
                MsgBox("Incorrect Answer")
                TextBox2.Clear()
                TextBox2.Focus()
                '  ErrorProvider1.Clear()
            Else
                MsgBox("The answer is correct. You can now change your password to 8-12 characters", MsgBoxStyle.Information, " Change Password")

            End If
            con.Close()
        End If
        reader.Close()
    Catch ex As Exception
        MsgBox("Error Connecting to Database: " & ex.Message)
    End Try

What issue are u facing now???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.