Adding data into a database using VB.net2005 and VS

jason1987

Member
Joined
Apr 15, 2007
Messages
14
Programming Experience
Beginner
I have got this code so far which takes a name and a score from texbox and a label, it works fine and stores within the database, however when i view the database on the actual game it dont update, i have to close it and relaunch the game for it to update, i believe i have to do sumit with clearing and loading the dataset where i put them comments, but unsure how i do this
VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Query1 As String = "INSERT INTO scoreboard (Name, Score) VALUES (@Name, @Score)"
        Dim cn As OleDb.OleDbConnection = _
New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Jason\Desktop\project1\project1\Highscores.mdb;User Id=admin;Password=;")
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(Query1, cn)
        cmd.Parameters.AddWithValue("@Name", Me.TextBox1.Text)
        cmd.Parameters.AddWithValue("@Score", Me.Label1.Text)
        Try
            cn.Open()
            cmd.ExecuteNonQuery()            
[SIZE=2]           highScoreForm.Query1TableAdapter.ClearBeforeFill(highScoreForm.HighscoresDataSet.Query1)[/SIZE]
            highScoreForm.Query1TableAdapter.Fill(highScoreForm.HighscoresDataSet.Query1)
            'clear.highscoresDataSet()
            'Load.highscoresDataSet()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            cn.Close()
        End Try
        highScoreForm.Show()
        Me.Hide()
    End Sub
]
 
Last edited:
I cant understand why youre mixing the old and new ways of doing data access.. Have a read of the DW2 link in my signature, section on updating data..
 
Back
Top