试图建立一个忘记密码VB表单。出现错误'在DataReader处于活动状态时无法设置CommandText'

时间:2016-10-30 07:13:37

标签: sql vb.net sqlite

下面是我的Visual Basic表单中的代码。我只是想学习Visual Basic。如果有人可以帮助我解决我的代码有什么问题,那就太好了。我也尝试了几种不同的方法,但我的Update查询似乎有一些重大问题。为了澄清一点,我的数据库表有以下列:MemberId,FirstName,LastName,StreetAddress,City,State,ZipCode,Email,Password

Imports System.Data.SQLite

Public Class ForgotPass
Public Sqlconn As New SQLiteConnection("Data Source = elibrary.db")

Public Function Hasconnection() As Boolean
    Try
        Sqlconn.Open()
        Sqlconn.Close()
        Return True
    Catch ex As Exception
        Return False

    End Try
End Function

Public MemberId As String
Dim MemberFirstName As String
Dim MemberLastName As String
Dim MemberAddress As String

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Me.Hide()
    LoginForm.Show()
End Sub

Private Sub SubmitBtn_Click(sender As Object, e As EventArgs) Handles SubmitBtn.Click
    If Hasconnection() = True Then
        MessageBox.Show("Successful Connection")
    Else
        MessageBox.Show("Unsuccessful")
    End If

    Dim sqlcmd2 As New SQLiteCommand("SELECT * FROM Member WHERE (FirstName = '" & FirstNametxt.Text & "' and LastName = '" & LastNametxt.Text & "' and StreetAddress = '" & StreetAddresstxt.Text & "' )", Sqlconn)

    Sqlconn.Open()
    Dim sqlreader As SQLiteDataReader = sqlcmd2.ExecuteReader()

    If sqlreader.Read() = True Then
        MemberId = sqlreader("MemberId").ToString()
        MemberFirstName = sqlreader("FirstName").ToString()
        MemberLastName = sqlreader("LastName").ToString()
        MemberAddress = sqlreader("StreetAddress").ToString()
        MessageBox.Show("Select successful" & "  " & MemberId & "  " & MemberFirstName & "  " & MemberLastName)
        Sqlconn.Close()

        Sqlconn.Open()
        If MemberFirstName = FirstNametxt.Text AndAlso MemberLastName = LastNametxt.Text AndAlso MemberAddress = StreetAddresstxt.Text Then

            sqlcmd2.CommandText = "UPDATE Member SET Password = '" & RetypeNewPassTxt.Text & "' WHERE FirstName = " & MemberFirstName & " AND LastName = " & MemberLastName & ""
            MessageBox.Show("Password Changed!")

            'Me.Hide()
            'ChangePasswordForm.Show()

        Else
            MessageBox.Show("Information Incorrect. Please try again.")


        End If

    End If

我有一个链接,可以显示一个忘记密码表单的例子,它也很棒。 谢谢

0 个答案:

没有答案