Hello,
Im just trying to get to grips with VB in Visual Studio 2008, the last version I used being VB6.
What I need is to be able to access a database stored in the same directory as the exe. I followed the Microsoft tutorial and set up a DataGridView and all the other bits. I then wrote my own function to add rows into the database (mods being the table within the database dlmods):
I now have two problems:
1. The first column is an autonumber one (ID). The dataview puts -1 into this column for a single row. When I run my addrow function I have to give it -2 (or whatever) as its ID to fill in, since -1 has already been used. The ....Fill line above reloads the database, demonstrating that Access has actually filled in the ID column with sensible numbers (7 and 8 I think). But of course, there should only be one column, the one that I added. The `empty` column that was there at the start has been saved and given a proper ID number, even though it should still register as empty.
2. Far more annoyingly, every time I modify any line of code that relates to the database and its various connection items, the whole database is cleared, which makes no sense to me whatsoever.
If anyone has any possible solutions to those problems, I would very much appreciate hearing them. I really dont want to have to resort to storing in and loading from text files. Basically I suppose, I am asking, what is the best way to link a VB program to a locally-stored database, for read and write access?
Thanks very much in advance, and please excuse any noobishness regarding VB in general!
Im just trying to get to grips with VB in Visual Studio 2008, the last version I used being VB6.
What I need is to be able to access a database stored in the same directory as the exe. I followed the Microsoft tutorial and set up a DataGridView and all the other bits. I then wrote my own function to add rows into the database (mods being the table within the database dlmods):
Code:
Public Sub addrow(ByVal i, ByVal ii, ByVal iii, ByVal iv, ByVal v, ByVal vi)
DlmodsDataSet.mods.Rows.Add(i, ii, iii, iv, v, vi)
Validate()
ModsBindingSource.EndEdit()
TableAdapterManager.UpdateAll(DlmodsDataSet)
ModsTableAdapter.Fill(DlmodsDataSet.mods)
End Sub
I now have two problems:
1. The first column is an autonumber one (ID). The dataview puts -1 into this column for a single row. When I run my addrow function I have to give it -2 (or whatever) as its ID to fill in, since -1 has already been used. The ....Fill line above reloads the database, demonstrating that Access has actually filled in the ID column with sensible numbers (7 and 8 I think). But of course, there should only be one column, the one that I added. The `empty` column that was there at the start has been saved and given a proper ID number, even though it should still register as empty.
2. Far more annoyingly, every time I modify any line of code that relates to the database and its various connection items, the whole database is cleared, which makes no sense to me whatsoever.
If anyone has any possible solutions to those problems, I would very much appreciate hearing them. I really dont want to have to resort to storing in and loading from text files. Basically I suppose, I am asking, what is the best way to link a VB program to a locally-stored database, for read and write access?
Thanks very much in advance, and please excuse any noobishness regarding VB in general!