簡體   English   中英

忘記密碼表格問題VB.net

[英]Forgot Password Form Issues VB.net

我正在嘗試為我的應用程序創建一個忘記密碼屏幕。 我在不同頁面上使用選項卡控件。 我當前的代碼可以創建用戶,但可以創建重復項(這是需要糾正的問題),然后我忘記密碼屏幕無法完全正常工作。

我的代碼是:

Imports System.Data.OleDb

Public Class Form2
Dim connection As New OleDb.OleDbConnection

Dim dbProvider As String
Dim dbSource As String
Dim MyDocumentsFolder As String
Dim TheDatabase As String
Dim FullDatabasePath As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim DBTest1 As String
Dim DBTestP1 As String
Dim cmd As New OleDbCommand(sql, connection)
Dim connStr As String
Dim usernamevalid As Integer
Dim passwordvalid As Integer

Public Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
    If User.Text.Length < 4 Then
        usernamevalid = 0
    ElseIf User.Text.Length > 4 Then
        usernamevalid = 1
    End If
    If Pass.Text.Length < 5 Then
        passwordvalid = 0
    ElseIf Pass.Text.Length > 5 Then
        passwordvalid = 1
    End If
    If usernamevalid = 0 Then
        MsgBox("Username Must Be At Least 5 Characters")
    End If
    If passwordvalid = 0 Then
        MsgBox("Password Must Be At Least 5 Characters")
    End If
    If passwordvalid And usernamevalid = 1 And Pass.Text = RePass.Text Then
        dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
        dbSource = "Data Source = C:\Users\Daniel\Documents\Robocopy.accdb"
        Dim connStr = dbProvider & dbSource

        DBTest1 = User.Text
        DBTestP1 = Pass.Text
        sql = "INSERT INTO Robocopy(username,[password],sq,sqa) VALUES('" & DBTest1 & "','" & DBTestP1 & "','" & SQREG.Text & "', '" & SQAREG.Text & "')"

        Using connection = New OleDb.OleDbConnection(connStr)
            Using cmd = New OleDb.OleDbCommand(sql, connection)
                connection.Open()
                cmd.ExecuteNonQuery()
                connection.Close()
                MsgBox("User Created!")
                'With cmd.Parameters
                '.AddWithValue("usernamer", DBTest.Text)
                '.AddWithValue("password", DBTestP.Text)
                '.AddWithValue("email", txtsub.text)
                '.AddWithValue("contactnum", txtau.text)
                'End With
                'cmd.ExecuteNonQuery()
            End Using
        End Using
    ElseIf Not Pass.Text = RePass.Text Then
        MsgBox("Passwords did not match")
    End If
End Sub

Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
    Dim result = MessageBox.Show(" Are you sure you want to quit", "Are you sure?", MessageBoxButtons.YesNoCancel)
    Me.Close()
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    If NewPass.Text = ReNewPass.Text Then
        Try
            connection.Open()
            cmd = New OleDbCommand("update robocopy set [password] = '" & NewPass.Text & "' where username = '" & UserFGT.Text & "'", connection)
            cmd.ExecuteNonQuery()
            MessageBox.Show("PASSWORD CHANGE SUCCESSFULLY")
            connection.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End If
End Sub
End Class

它捕獲的異常是ConnectionString屬性尚未初始化

目前,我已將代碼更改為我認為的含義:

Button4的代碼已作如下更改:

   Private Sub ResetPassword_Click(sender As Object, e As EventArgs) Handles ResetPassword.Click
    If NewPass.Text = ReNewPass.Text Then
        Using connection = New OleDb.OleDbConnection(connStr)
            Using cmd = New OleDb.OleDbCommand(sql, connection)
                connection.Open()
                cmd = New OleDbCommand("update robocopy set [password] = '" & NewPass.Text & "' where username = '" & UserFGT.Text & "'", connection)
                cmd.ExecuteNonQuery()
                MessageBox.Show("PASSWORD CHANGE SUCCESSFULLY")
                connection.Close()
            End Using
        End Using

    End If
End Sub

我現在收到以下錯誤:cmd = New OleDbCommand(“ update robocopy set [password] ='”&NewPass.Text&“'其中username ='”&UserFGT.Text&“'”,連接)我正在獲取以下錯誤: cmd表示“只讀”變量不能作為分配目標

我唯一看不到的連接字符串錯誤是'Data Source ='之后的多余空格。

這是來自connectionstrings.com的示例:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;Persist Security Info=False;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM