I have a simple blackjack game that I am trying to get to update a database by adding 2 simple values to it. I want it to add the username and the players' score to the database.
After watching an online tutorial this is the code I tried:
Imports System.Data.OleDb
Public Class Form1
'for updating database
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub ButtonSaveScore_Click(sender As Object, e As EventArgs) Handles ButtonSaveScore.Click
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
dataFile = "F:\Documents\Class Documents\CSC289 - K6A - Programming Capstone Project\Project\BlackJack\BlackJack\Scoreboard.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "Update [Scores] set [UserName] = '" & playerName & "',[Score] =' " & wins & "' where [ID] = NEW"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
myConnection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
I get the error:
one or more variables is not provided
The first time I hit the save button. The second time it breaks the application and it says that I "cannot adjust the files current state it is already open. It then highlights myConnection.ConnectionString = connString
.