asp.net.vb 不存在数据时读取尝试无效

发布于 2024-11-24 04:43:59 字数 1274 浏览 0 评论 0原文

我不确定为什么这段代码不起作用 我已经根据表字段数据进行了跟踪,但我仍然无法让 SQL Datareader 工作。我已经检查了表格和所有数据字段,一切都正确。但我仍然无法从数据库中读取数据。帮助TT

    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()

I am not sure why this code doesn't work
I have follow according to the table field data and it I am still unable to get the SQL Datareader to work. I have checked the tables and all datafields, everything is correct. But I still am unable to read data from the database. Help 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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七七 2024-12-01 04:43:59

使用 MySql 进行测试:出现 SQL 语法不正确的错误。

然后我删除了[]并且它起作用了。

SqlServer 怎么样?我想说,至少尝试一下。

Testing with MySql: I get an error that the SQL syntax is not correct.

I then removed the [ ] and it works.

How is that with SqlServer? Try at least, i'd say.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文