Dim total As Integer
Dim t As Integer
Dim connection As New OleDb.OleDbConnection(connStr)
Dim updateOlebCommand As New OleDb.OleDbCommand
'get places left'
counttable.Clear()
sqlStr = "SELECT * FROM tblStudent WHERE OptionTaken = 'Games Programming'"
dataadapter = New OleDb.OleDbDataAdapter(sqlStr, connStr)
dataadapter.Fill(counttable)
dataadapter.Dispose() 'good practice
t = counttable.Rows.Count
MessageBox.Show("the total is " & t)
total = (30 - t)
'end of places'
'insert places'
myTable.Clear()
sqlStr = "UPDATE tblStudent SET PlacesLeft= '" & total & "' WHERE MOption = 'Games Programming'"
connection.Open()
updateOlebCommand.Connection = connection
updateOlebCommand.CommandText = sqlStr
dataadapter.InsertCommand = updateOlebCommand
dataadapter.InsertCommand.ExecuteNonQuery()
connection.Close()
End Sub