Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Code: Imports System.Data.OleDb Public Class Form0 Dim connection As New OleDbCo

ID: 3548889 • Letter: C

Question

Code:


Imports System.Data.OleDb

Public Class Form0

    Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=loginUser.mdb;")
    Dim command As New OleDbCommand("SELECT [ID] FROM [Staff] WHERE [usernameField] = username AND [passwordField] = password", connection)
    Public Dad As OleDbDataAdapter
    Public Dst = New DataSet
    Dim CurrentRow As Integer

    Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click

        txtUsername.Focus()

        Dim usernameParam As New OleDbParameter("username", Me.txtUsername.Text)
        Dim passwordParam As New OleDbParameter("password", Me.txtPassword.Text)

        command.Parameters.Add(usernameParam)
        command.Parameters.Add(passwordParam)

        command.Connection.Open()

        Dim i As Integer
        Dim j As Integer
        Dim searchPass As String

        Try
            searchPass = txtPassword.Text
            j = Dst.Tables("Staff").Rows.Count - 1
            i = 0
            While i <> j + 1
                If searchPass = Dst.Tables("Staff").Rows(i)("password") Then

                    Exit While

                ElseIf i = j Then

                    MsgBox("Not")

                    Exit While
                End If
                i += 1
            End While
            CurrentRow = i
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        command.Connection.Close()

        Dim cb As New OleDb.OleDbCommandBuilder(Dad)

        Dst.Tables("Staff").Rows(CurrentRow).Item(2) = txtNewPassword.Text

    End Sub

End Class


Can help me correct my edit password code?

Explanation / Answer


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



image1.Visible = True


Me.WindowState = 2

image1.Width = 16000

image1.Height = 10000




'GroupBox1.Hide()

End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim tim As Date

tim = Date.Now()



txttime.Text = tim.ToShortTimeString

txttime.Show()

End Sub


Private Sub btnaccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaccept.Click


Validation()



End Sub



Private Sub CheckLogin()

Dim connStr As String

Dim selectSQL As String = "SELECT Username,Password FROM dbo.StudentLogin"

Dim con As SqlConnection

Dim cmd As SqlCommand

Dim reader As SqlDataReader

Dim boolOK As Boolean

Dim countLoginFail As Integer




'connStr = ConfigurationSettings.AppSettings.Item("ConnectionString")

con = New SqlConnection("SERVER=(local);DATABASE=Northwind;UID=sa;PWD=5105;")

selectSQL = "SELECT Username,Password FROM dbo.StudentLogin"

cmd = New SqlCommand(selectSQL, con)

con.Open()

reader = cmd.ExecuteReader()



Do While reader.Read = True


If Trim(txtusername.Text) = Trim(reader("Username")) Then


If Trim(txtusername.Text) = Trim(reader("Username")) And Trim(txtpassword.Text) = Trim(reader("Password")) Then


MsgBox("You are Success")


Exit Do

Else


MsgBox("Your Username or Password is invalid, please try again !")

txtpassword.Text = ""

CheckLoginFail()

Exit Do

End If

End If




Loop


reader.Close()

btnaccept.Focus()


End Sub


Private Function Validation() As Boolean

Validation = False


If txtusername.Text = "" Then

MsgBox("Username cannot be blank")

txtpassword.Text = ""

Exit Function

ElseIf txtpassword.Text = "" Then

MsgBox("Password cannot be blank")

txtusername.Text = ""

Exit Function

End If


Validation = True

CheckLogin()



End Function



Private Sub btnchange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnchange.Click

Dim b As New Form2()


Me.Hide()

b.Show()

End Sub


Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click

End

End Sub


End Class