【问题标题】:how to display msg in textbox if the selected record could not be found in database如果在数据库中找不到所选记录,如何在文本框中显示消息
【发布时间】:2010-12-16 06:45:24
【问题描述】:

我有两个文本框和 1 个按钮...

当我在 textbox1 中输入旅行 ID 并单击 button1 然后在 textbox2 中我根据我在 textbox1 中输入的旅行 ID 检索旅行社名称时,我正在做,

我希望根据我在 textbox1 中输入的旅行 ID 未找到任何记录,然后在 textbox2 中显示消息未找到记录...

这是我用来通过在 textbox1 中输入旅行 ID 来检索 textbox2 中记录的编码:看看...

请根据我上面的查询重新编辑此代码:

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim SQLData As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True")
        Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT * FROM a1_vendors WHERE VendorId ='" & TextBox1.Text & "'", SQLData)

        SQLData.Open()
        Dim dtrReader As System.Data.SqlClient.SqlDataReader = cmdSelect.ExecuteReader()
        If dtrReader.HasRows Then
            While dtrReader.Read()
                TextBox2.Text = dtrReader("travels")
            End While
        Else
            '
        End If

        dtrReader.Close()
        SQLData.Close()
        End Sub

【问题讨论】:

  • 空的ELSE 块中的TextBox2.Text = "No records found" 怎么样

标签: asp.net vb.net


【解决方案1】:

最简单的方法是在else块中添加:

TextBox2.Text="未找到记录"。

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 2019-08-06
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多