Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net.vb在没有数据时尝试读取无效_Asp.net_Sql_Database_Vb.net_Sqldatareader - Fatal编程技术网

asp.net.vb在没有数据时尝试读取无效

asp.net.vb在没有数据时尝试读取无效,asp.net,sql,database,vb.net,sqldatareader,Asp.net,Sql,Database,Vb.net,Sqldatareader,我不知道为什么这个代码不起作用 我已经根据表字段数据进行了跟踪,但仍然无法使SQL Datareader正常工作。我已经检查了表和所有数据字段,一切都是正确的。但我仍然无法从数据库中读取数据。帮助T.T Dim connectionString = ConfigurationManager.ConnectionStrings("CleanOneConnectionString").ConnectionString Dim myConn As New SqlConnection(c

我不知道为什么这个代码不起作用 我已经根据表字段数据进行了跟踪,但仍然无法使SQL Datareader正常工作。我已经检查了表和所有数据字段,一切都是正确的。但我仍然无法从数据库中读取数据。帮助T.T

    Dim connectionString = ConfigurationManager.ConnectionStrings("CleanOneConnectionString").ConnectionString
    Dim myConn As New SqlConnection(connectionString)
    myConn.Open()
    Dim cmd = "Select * from [Member] where Email = @Email"
    Dim myCmd As New SqlCommand(cmd, myConn)
    myCmd.Parameters.AddWithValue("@Email", emailBox.Text)
    Dim objReader As SqlDataReader

    objReader = myCmd.ExecuteReader()
    objReader.Read()
    Result.Text = " " 'initialise label to show correct message for available or found


    'Check the reader see if any  record found matching WHERE
    If (objReader.Read()) Then
        'read=true, check Password
        'Dim tpassword As String = objReader.GetString(5)
        'If tpassword = passwordBox.Text Then
        'Result.Text = "** Login Succcessful **"
        Result.Text = objReader.GetString(1)
        'Else
        'Result.Text = "Invalid Password" & objReader.GetString(5) & passwordBox.Text
        'End If
        'reader=false, no such records matching WHERE
    Else
        Result.Text = objReader.GetString(1)
    End If
    myCmd.Dispose()
    myConn.Dispose()

使用MySql测试:我得到一个错误,SQL语法不正确

然后我删除了[],它就可以工作了


SqlServer的情况如何?我想说,至少尝试一下。

当您运行原始SQL(使用SQL profiler查看)时,是否从数据库中返回了任何行?它进入循环了吗?对于这一个,没有,但我确信我可以通过SQLDataReader获取行,对于这一个,我似乎无法检索任何行。我已经试过无数次了