Hello first of all thanks for your time
I am programming an app that makes use of an Acces database
Table Players
id Players Password Turn Moves
1 new 'empty' true 3
Table Map
id Regio Eigenaar Troepen
1 Alaska "empty" 0
2 NoordCanada "Empty" 0
...
40 IndoChina "Empty" 0
In my Application I first add 3 (to add 3 players) and then I put the data set In a DataGridView so you can adjust the names of the players the regions they own etc
this all happens in the following code
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Public da As New OleDb.OleDbDataAdapter
Public ds As New DataSet
Dim sql As String
Public cb As New OleDb.OleDbCommandBuilder(da)
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "PROVIDER=microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source = "
con.ConnectionString = dbProvider & dbSource & Form1.dbPath & "\Risk.accdb"
con.Open()
sql = "SELECT * FROM Map"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Map")
Sql = "SELECT * FROM Players"
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "Players")
con.Close()
For i = 2 To Form3.MaxPlayersBox.Maximum
ds.Tables("Players").Rows.Add(i)
'Dim cb As New OleDb.OleDbCommandBuilder(da)
'da.Update(ds, "Players")
Next i
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Players"
End Sub
Private Sub PLayersB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PLayersB.Click
DataGridView1.DataMember = Nothing
DataGridView1.DataMember = "Players"
End Sub
Private Sub MapB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MapB.Click
DataGridView1.DataMember = Nothing
DataGridView1.DataMember = "Map"
RandomizeB.Visible = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RandomizeB.Click
If MsgBox("heb je alle spelers toegevoegd?", vbYesNo) = vbNo Then
Exit Sub
End If
Dim P As Integer = 0
Dim RandInt As New Random
Dim Rand As Integer
For i = 0 To 39
Rand = RandInt.Next(0, 39)
line34: If ds.Tables("Map").Rows(Rand).Item("Eigenaar").ToString = "" Then
ds.Tables("Map").Rows(Rand).Item("Eigenaar") = ds.Tables("Players").Rows(P).Item("Players")
ElseIf Rand < 39 Then
Rand += 1
GoTo Line34
Else
Rand = 0
GoTo line34
End If
P += 1
If P > ds.Tables("Players").Rows.Count - 1 Then
P = 0
End If
Next i
RandomizeB.Visible = False
End Sub
Private Sub SaveB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveB.Click
con.Open()
sql = "SELECT * FROM Map"
da = New OleDb.OleDbDataAdapter(sql, con)
Dim cb As New OleDb.OleDbCommandBuilder(da)
da.Update(ds, "Map")
sql = "SELECT * FROM Players"
da = New OleDb.OleDbDataAdapter(sql, con)
Dim cb2 As New OleDb.OleDbCommandBuilder(da)
da.Update(ds, "Players")
'The problem is right here
Me.Close()
End Sub
So theDataSet I update has become
Table Players
id Players Password Turn Moves
1 Player1 'empty' true 3 2 Player2 'empty' False 0 3 Player3 'empty' False 0 4 Player4 'empty' False 0
Table Map
id Regio Eigenaar Troepen
1 Alaska "Player2" 0
2 NoordCanada "Player3" 0
...
40 IndoChina "Player1" 0
When I try to update the database (private sub SaveB_Click) I get an error:
da.Update(ds,"Players"): Instruction INSERT INTO contains a syntax error
I have been researching on the internet for a week now but I just don't know what to do
The database is saved in a shared Dropbox folder BTW. (that's what gives my game an online multiplayer feature)
Thank U and if you need more information I'll be available the rest of the day.