转换为long类型的字符串无效。当我使用组合框来运行程序时,它确实有效

时间:2016-10-07 09:02:58

标签: vb.net

当我使用组合框选择表名并且它不起作用并显示错误消息为"转换字符串到long类型无效"。有人帮我吗?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

    lblError1.Text = ""
    lblError2.Text = ""
    Dim con As New OleDb.OleDbConnection
    Dim str As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=..\VisitorPass.accdb"
    con = New OleDbConnection(str)
    Dim sql As String = "select AccountName,[Password] from [" & ComboBox1.SelectedItem.trim().ToString() & "] where AccountName='" & txtName.Text.Trim().ToString() & "'and [Password]='" & txtPassword.Text.Trim().ToString() & "'"
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim obj As New VisitorProfile

    cmd = New OleDbCommand(sql, con)
    con.Open()
    dr = cmd.ExecuteReader()
    Try

        If txtName.Text.Trim().ToString() = "" Then
            lblError2.Text = ""
            lblError1.Text = "pls write name"
        ElseIf txtPassword.Text.Trim().ToString() = "" Then
            lblError1.Text = ""
            lblError2.Text = "pls write password"
            'ElseIf Not dr.HasRows = txtName.Text.Trim() Then
            '    lblError1.Text = "your Account is incorrect"
            ' ElseIf Not dr.HasRows = txtPassword.Text.Trim() Then
            '      lblError2.Text = "your Password is incorrect"
        ElseIf Not ComboBox1.SelectedItem.ToString() Then

            MsgBox("Sorry Please try again !", MsgBoxStyle.OkOnly, "Invalid Login")

        ElseIf Not dr.HasRows Then

            MsgBox("Sorry Please try again !", MsgBoxStyle.OkOnly, "Invalid Login")

        ElseIf dr.Read Then

            txtName.Text = dr("AccountName").ToString()
            txtPassword.Text = dr("Password").ToString()
            obj.StringPass = txtName.Text
            MsgBox("welcome")
            obj.Show()
            VisitorProfile.lblwelcome.Text = txtName.Text
            Me.Hide()

        Else
            con.Close()
            MsgBox("Sorry Please try again", MsgBoxStyle.OkOnly, "invalid login")


        End If

    Catch ex As Exception

        MessageBox.Show(ex.Message)

    End Try



End Sub

0 个答案:

没有答案