一旦此表格再次弹出,如何使您的显示数据有所不同?

发布于 2025-02-01 07:53:41 字数 2233 浏览 1 评论 0原文

我是vb.net的新手,我真的很难解决这个问题。我想通过在我的RichTextbox和Radio Butactons中逐一显示该表格,以获取所有行是“逻辑推理”,一旦此表格再次通过Next Next按钮显示。我正在使用XAMPP进行数据库和Visual Studio VB.NET。希望您能为此提供帮助。先感谢您。这是我的数据库连接模块中的代码:

    Private dbConn As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=quiz;Convert Zero DateTime=True")
    Private qreader As MySqlDataReader
    Private cmd As MySqlCommand = New MySqlCommand

    Public Sub displayData(ByRef richText As RichTextBox, ByRef radiobtnA As RadioButton, ByRef radiobtnB As RadioButton, ByRef radiobtnC As RadioButton, ByRef radiobtnD As RadioButton, ByRef sql As String)
        Try
            cmd.Connection = dbConn
            openConnection()
            cmd.CommandText = sql
            qreader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

            While qreader.Read
                richText.Text = (qreader("Question").ToString)
                radiobtnA.Text = (qreader("Choice A").ToString)
                radiobtnB.Text = (qreader("Choice B").ToString)
                radiobtnC.Text = (qreader("Choice C").ToString)
                radiobtnD.Text = (qreader("Choice D").ToString)
            End While

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
        End Try
        qreader.Close()
        closeConnection()
    End Sub
    ReadOnly Property getConnection() As MySqlConnection
        Get
            Return dbConn
        End Get
    End Property

    Sub openConnection()
        If dbConn.State = ConnectionState.Closed Then
            dbConn.Open()
        End If
    End Sub

    Sub closeConnection()
        If dbConn.State = ConnectionState.Open Then
            dbConn.Close()
        End If
    End Sub
End Module ```



Here is the code in my form that I want to display the data with:

```Public Class quizForm
    Dim sql As String

Private Sub quizForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        sql = "SELECT * FROM `examquestion` WHERE `Exam Category` = 'Logical Reasoning'"
        displayData(rtxtQuestion, rbnA, rbnB, rbnC, rbnD, sql)

    End Sub```

The code is working but only displayed the first row of category Logical Reasoning. 

I am new to VB.net and I really had a hard time to this problem. I want to fetch all rows where the statement is "Logical Reasoning" by displaying it one by one in my richtextbox and radio buttons once this form show up again through next button. I am using xampp for my database and visual studio vb.net. I hope you can help me with this. Thank you in advance. Here is my code in my database connection module:

    Private dbConn As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=quiz;Convert Zero DateTime=True")
    Private qreader As MySqlDataReader
    Private cmd As MySqlCommand = New MySqlCommand

    Public Sub displayData(ByRef richText As RichTextBox, ByRef radiobtnA As RadioButton, ByRef radiobtnB As RadioButton, ByRef radiobtnC As RadioButton, ByRef radiobtnD As RadioButton, ByRef sql As String)
        Try
            cmd.Connection = dbConn
            openConnection()
            cmd.CommandText = sql
            qreader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

            While qreader.Read
                richText.Text = (qreader("Question").ToString)
                radiobtnA.Text = (qreader("Choice A").ToString)
                radiobtnB.Text = (qreader("Choice B").ToString)
                radiobtnC.Text = (qreader("Choice C").ToString)
                radiobtnD.Text = (qreader("Choice D").ToString)
            End While

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
        End Try
        qreader.Close()
        closeConnection()
    End Sub
    ReadOnly Property getConnection() As MySqlConnection
        Get
            Return dbConn
        End Get
    End Property

    Sub openConnection()
        If dbConn.State = ConnectionState.Closed Then
            dbConn.Open()
        End If
    End Sub

    Sub closeConnection()
        If dbConn.State = ConnectionState.Open Then
            dbConn.Close()
        End If
    End Sub
End Module ```



Here is the code in my form that I want to display the data with:

```Public Class quizForm
    Dim sql As String

Private Sub quizForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        sql = "SELECT * FROM `examquestion` WHERE `Exam Category` = 'Logical Reasoning'"
        displayData(rtxtQuestion, rbnA, rbnB, rbnC, rbnD, sql)

    End Sub```

The code is working but only displayed the first row of category Logical Reasoning. 

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文