一旦此表格再次弹出,如何使您的显示数据有所不同?
我是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论