我有一个包含大约 30 个问题的 Access 数据库。数据库分为3个表;问题,可能的答案和答案。这些问题有 2 到 5 个可能的答案。如何从我的数据库中随机选择 10 个问题并将它们添加到我的 vb 表单中?
PS:这是我第一次这样做
这是我的代码
Dim provider As String
Dim dataFile As String
Dim connString As String
Public myConnection As OleDbConnection = New OleDbConnection
Public dr As OleDbDataReader
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
dataFile = "C:\Users\Phil\Desktop\Questions.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "SELECT Top 10 ID_Question From Questions ORDER BY RND(ID_Question)"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr("ID_Question").ToString
End While
myConnection.Close()
MsgBox("fsafa")
End Sub
文本框不改变,msgBox 不显示
如果有人感兴趣,对我有用的解决方案
SELECT Top 10 ID_Question, Question_Name
FROM tblQuestions
ORDER BY RND(-(100000*ID_Question)*Time())