当前位置:编程学习 > C#/ASP.NET >>

为什么执行下面的代码出现:不存在的行/列数据 的提示???困扰好长时间了

Imports System.Data
Imports System.Data.OleDb
Public Class frmlogin

    

    Private Sub btnok_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnok.Click
        If UserAndPwdcheck() Then
            Dim conndbstr, selectcmd, limitflag As String
            If RadioBtnSuper.Checked = True Then
                limitflag = RadioBtnSuper.Text
            End If
            If RadioBtnSystem.Checked = True Then
                limitflag = RadioBtnSystem.Text
            End If
            If RadioBtnDo.Checked = True Then
                limitflag = RadioBtnDo.Text
            End If
            'selectcmd = "select * from login_db where username=' " & txtusername.Text & " 'and password=' " & txtuserpwd.Text & " '"
            selectcmd = "select * from logindb where 用户 = ' " & txtusername.Text & " ' And  密码 = ' " & txtuserpwd.Text & " ' "
            conndbstr = " provider=microsoft.jet.oleDb.4.0;data source= " & CurDir() & "\lxbch.mdb;"   '" & Application.StartupPath & "\lxbch.mdb;"
            conndbstr = conndbstr & "jet oleDb:database password=9765"

            Try
                Dim conn As OleDbConnection
                Dim cmd As OleDbCommand
                Dim myreader As OleDbDataReader
                '*******************
                conn = New OleDbConnection(conndbstr)
                conn.Open()
                '*******************
                cmd = New OleDbCommand(selectcmd, conn)
                'cmd.CommandType = CommandType.Text
                '*******************
                myreader = cmd.ExecuteReader()

                'While 
                '*********待写代码********
                If myreader.Item("用户") = txtusername.Text And myreader.Item("密码") = txtuserpwd.Text Then   'myreader.Read()And myreader.Item("flag") = limitflag Then
                    frmmainshow()
                    Me.Close()
                Else
                    '.....
                    MsgBox(" 请检查密码和用户名及其权限,重新输入。", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "登录失败")
                End If
                'End While
                conn.Close()
                myreader.Close()
                myreader.Dispose()


            Catch e1 As Exception
                MessageBox.Show(e1.Message)

            End Try


        End If
    End Sub
    Public Function UserAndPwdcheck() As Boolean
        If txtusername.Text = "" And txtuserpwd.Text = "" Then
            ErrorProvider1.SetError(txtusername, "没有输入账号")
            ErrorProvider2.SetError(txtuserpwd, "没有输入密码")
            MessageBox.Show("没有输入[账号]和[密码]", "输入检查", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
            Exit Function
        End If

        If txtusername.Text = "" Then
            ErrorProvider1.SetError(txtusername, "没有输入账号")
            ErrorProvider2.SetError(txtuserpwd, "")
            MessageBox.Show("没有输入[账号]", "输入检查", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
            Exit Function
        End If
        If txtuserpwd.Text = "" Then
            ErrorProvider1.SetError(txtusername, "")
            ErrorProvider2.SetError(txtuserpwd, "没有输入密码")
            MessageBox.Show("没有输入[密码]", "输入检查", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
            Exit Function
        End If
        If RadioBtnSuper.Checked = False And RadioBtnSystem.Checked = False And RadioBtnDo.Checked = False Then

        End If
        If txtusername.Text <> "" And txtuserpwd.Text <> "" And RadioBtnSuper.Checked = False And RadioBtnSystem.Checked = False And RadioBtnDo.Checked = False Then
            MsgBox(" 请检查密码和用户名及其权限1,重新输入。", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "登录失败")
        ElseIf txtusername.Text <> "" And txtuserpwd.Text <> "" Then
            ErrorProvider1.SetError(txtusername, "")
            ErrorProvider2.SetError(txtuserpwd, "")
            UserAndPwdcheck = True
        End If
    End Function
    Public Sub frmmainshow()
        Dim mainfrm As New frmmain

        mainfrm.ShowDialog(Me)

    End Sub

    Private Sub txtuserpwd_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtuserpwd.TextChanged

    End Sub
End Class --------------------编程问答-------------------- 哪行代码标注下。 --------------------编程问答-------------------- 改成这样试下
If myread.Read Then
     myread.Close()
     frmmainshow()
     Me.Close() 
Else
    '..... 
    MsgBox(" 请检查密码和用户名及其权限,重新输入。", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "登录失败") 
End If 
--------------------编程问答-------------------- myreader = cmd.ExecuteReader() 

myreader.Read() 
  
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 

http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- 按楼上两位说的改过之后还是不行。


就是读不出数据来。。。。郁闷
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,