Pete_M

I have a dataset that i am updating during runtime of my program.  To do this, I first delete all of the data in a datatable using "DELETE * FROM Table1" command, and then updating the dataset.  To initiate the update, i double click on a datagrid.  The first time i double-click on the data grid, the program works exactly as planned--i step through the code and verify that first all the records in the datatable delete, and then is updated with all the new records.  The problem i'm having is that the next time i double-click on the datagrid, the table doesn't delete!   Why would this happen   Here's my code:

Sub UpdateTeamTable()

Dim dt As New DataTable

Dim strSQL As String

Dim int1 As Integer, int2 As Integer

dt = Main.FantasyDataSet.Teams

Dim oCon As New OleDb.OleDbConnection (My.Settings.FantasyConnectionString)

Dim oCommand As New OleDb.OleDbCommand

Dim oAdpt As New OleDbDataAdapter

oCon.Open()

strSQL = "DELETE * FROM Teams"

oCommand = New OleDbCommand(strSQL, oCon)

oAdpt = New OleDbDataAdapter(oCommand)

oAdpt.Fill(dt) 'the second time i try to update dt, nothing happens!!!!

oAdpt.Update(dt)

oCon.Close()

'routine for updating dt goes here and seems to be working just fine....

Main.TeamsTableAdapter.Update(dt)

End Sub

Thanks in advance for the help!

Pete M



Re: Visual Basic Express Edition Table only updates once during runtime...

ahmedilyas

the command should be, im hoping its a typo, DELETE FROM Teams

now I am wondering if you are seeing changes not happening during your run (in the same session) or when you stop and run again from the IDE






Re: Visual Basic Express Edition Table only updates once during runtime...

Pete_M

not a typo. I thought the '*' is a wild card that would mean DELETE 'every record' FROM Teams.

I've added a break before and after the line oAdpt.fill(dt). Before it, dt = the orig Teams datatable, and after it dt has 0 records. So it seems to be deleting corretly. Then when i continue the run, I add rows to dt and update the table again. And i'm positive the new records are saved to the table in my output folder. But again this only happens for the first time i try and update the records (using a double-click on the datagrid--see orig post).

The second time i double-click i get an error saying i am inserting a record that's not unique in the row that's a data-key.





Re: Visual Basic Express Edition Table only updates once during runtime...

Pete_M

anyone out there know why this is happening



Re: Visual Basic Express Edition Table only updates once during runtime...

Bruno Yu - MSFT

Pete_M,

This problem caused by DataGrid control. Actually, I have a project that contains the modify and save functions. When you have modified data shown in the DataGrid, then you should leave the highlight item to other items then click save, the Save method can work normally.

I don't think there is something wrong with your SQL statement, just pay more attention when you operating the datagrid control and check the change in the database table. If there is still something wrong, please run the program again and check the result.