0
我正在爲學校的VB項目工作。這是一個貪吃蛇遊戲,我將高分存儲在數據庫中。我需要知道如何從數據集中插入和刪除記錄,以便我可以擺脫舊的低分並插入新的高分。我們在課堂上只簡單地介紹了LINQ,所以我非常無知。使用linq從數據集中刪除和插入記錄?
這是我到目前爲止,它的一切工作。
Private Sub HighScores_Load(sender As System.Object, e As System.EventArgs)
Handles MyBase.Load
'See if player score is higher than the low score, and if so, add player name and score to database
Me.HighscoresTableAdapter.Fill(Me.VbprojectDataSet.highscores)
Dim lowScore = Aggregate scores In VbprojectDataSet.highscores
Select scores.score
Into Min()
If GridForm.player.score > lowScore Then
Dim lowScoreRow = From scores In VbprojectDataSet.highscores
Where scores.score = lowScore
Select scores
GridForm.player.name = InputBox("You got a new high score! What is your name?", "SnakE")
End If
End Sub
爲什麼使用LINQ進行這樣的數據庫操作?它是nessessery條件之一嗎?在這種情況下,普通香草ADO.NET會簡單得多。 – 2013-05-03 19:12:34
正在使用數據集的要求?如果是這樣,我認爲最好使用數據集本身來更改和保存數據。如果沒有,你可以考慮使用[linq-to-sql](http://www.ezzylearning.com/tutorial.aspx?tid=1787244)。這真的不難學,但它當然是基於LINQ的,所以可能是目前爲止的一個橋樑。 – 2013-05-03 20:12:40
這是一個涵蓋很多不同主題的基礎課程。我們幾乎沒有涉及在我們的應用程序中使用數據庫。唯一的要求是我們有一個數據庫綁定到我們的應用程序中。感謝您的意見。 – 2013-05-04 21:25:37