我制作了一個抽認卡應用程式,將用戶抽認卡存盤到一個訪問資料庫中,他們將能夠從中進行修改。
這是創建抽認卡的部分代碼
command = " insert into Flashcards ([Front],[Back],[Difficulty]) values ('" & txtFront.Text & "','" & txtBack.Text & "' ,'" & 3 & "')"
這將抽認卡存盤在以下資料庫 Access 資料庫中
這是修改抽認卡的部分代碼
Private Sub btnEasy_Click(sender As Object, e As EventArgs) Handles btnEasy.Click
Dim index = rand.Next(dt.Rows.Count) ' generates index in the range 0 .. Count - 1
If txtBack.Visible = True Then 'If the back of the flashcard is shown
txtFront.Text = dt.Rows(index)(2).ToString() 'Displays a random record in the third column (front of flashcard)
txtBack.Visible = False 'Does not display the back of the flashcard
txtBack.Text = dt.Rows(index)(3).ToString() 'Displays a random record in the fourth column ()
Else 'If the user has not pressed the reveal button before
MsgBox("Please first reveal the back of the flashcard")
End If
End Sub
Private Sub btnGood_Click(sender As Object, e As EventArgs) Handles btnGood.Click
Dim index = rand.Next(dt.Rows.Count) ' generates index in the range 0 .. Count - 1
If txtBack.Visible = True Then
txtFront.Text = dt.Rows(index)(2).ToString()
txtBack.Visible = False
txtBack.Text = dt.Rows(index)(3).ToString()
Else
MsgBox("Please first reveal the back of the flashcard")
End If
End Sub
Private Sub btnHard_Click(sender As Object, e As EventArgs) Handles btnHard.Click
Dim index = rand.Next(dt.Rows.Count) ' generates index in the range 0 .. Count - 1
If txtBack.Visible = True Then
txtFront.Text = dt.Rows(index)(2).ToString()
txtBack.Visible = False
txtBack.Text = dt.Rows(index)(3).ToString()
Else
MsgBox("Please first reveal the back of the flashcard")
End If
End Sub
現在 btnEasy , btngood 和 btnhard 都做同樣的事情,但我想知道一種方法,例如按 btnEasy 會將資料庫中的難度從 3 更改為 1。
另外,我如何得到它,所以按 btneasy 只會隨機選擇難度為 1 的抽認卡,而不僅僅是從整個資料庫中隨機選擇一張抽認卡。
對不起,如果問題有點長,我已經被困在這個問題上很長一段時間了
uj5u.com熱心網友回復:
您需要過濾資料表(代碼中的 dt)以僅選擇與給定按鈕的“難度”相關的記錄。從你的圖片來看,Easy = 1,Good = 2,Hard = 3?如果您不熟悉從 DataTable 中選擇資料子集,它在您的代碼中應該如下所示:
' Use the Select method to find all rows matching the filter.
hardRows = dt.Select("Difficulty = 3")
然后您可以從該子集或行(而不是從 dt.Rows.Count)中隨機選擇。
此外,有關更多資訊,請查看 Microsoft 的此檔案:https : //docs.microsoft.com/en-us/dotnet/api/system.data.datatable.select
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/351525.html
標籤:网络
