Updating Dataset

xzibited2

Active member
Joined
Jul 9, 2008
Messages
26
Programming Experience
1-3
Running VB.NET 2008 Express. I have an Access database connected to my app. Whenever I change data in Access, it does not update the dataset. I know why this is happening, just don't know how to correct it. Help!
 
You're going to have to provide further information. Do you really mean whenever you change data or do you actually mean when you change the schema? Data is the values stored in the rows of the tables. The schema is the tables themselves and the columns they contain. Can you give an example of what you're doing and what you expect to happen that doesn't?
 
I have the same problem too. I am using an SQL table, and when i edit the table DEFINITION, for example the name os a column, the changes don't take effect in the dataset! Thanks,
Hugo
 
I have the same problem too. I am using an SQL table, and when i edit the table DEFINITION, for example the name os a column, the changes don't take effect in the dataset! Thanks,
Hugo
Nor are they supposed to. The DataSet is not specifically linked to the database. The DataSet schema is created based on the database schema at the time you run the Data Source Wizard. If you change the database schema and you want to change the DataSet to match then you need to run the Data Source Wizard again. You can do that by selecting the Data Source in the Data Sources window and pressing the Configure button.

Note that existing columns may not be affected by the wizard. If a table has changed your best bet is to delete it first in the DataSet designer and then let the Data Source Wizard add it again.
 
Yes, i understand, but what I am saying is that even if I delete and add the a new data source, the data won't update and will still be the same as the first time I created a dataset in that project. The only way I can make the changes take effect, is by creating a new project. I don't really understand if this is supposed to be this way or not.

For example, I also used a link to an object I created, and there was an error because one of the classes had a list of Component instead of a list of Components which was what I had created, and so the dataset appeared wrong. Even if i deleted it, corrected the code in the class, and readded it, it still would be a list of Component...
 
Yes, i understand, but what I am saying is that even if I delete and add the a new data source, the data won't update and will still be the same as the first time I created a dataset in that project. The only way I can make the changes take effect, is by creating a new project. I don't really understand if this is supposed to be this way or not.

For example, I also used a link to an object I created, and there was an error because one of the classes had a list of Component instead of a list of Components which was what I had created, and so the dataset appeared wrong. Even if i deleted it, corrected the code in the class, and readded it, it still would be a list of Component...
That's simply not possible so you must be doing something wrong, or else your VS installation is corrupt in some way. When you create a Data Source it gets its schema from the database so, if you change the schema, there's no way for a DataSet to be created with the old schema because there's nowhere for the wizard to read that old schema from. Please describe the EXACT steps you took to update the schema.
 
Here's a scenario; Using VB 2008 (Express) you can use Database Explorer to create a new connection, here you can write a new db name and it creates one in Documents folder (see "modify connection, advanced" or look in properties window), the connection is named for example "db.mdf". The first time adding this as Data Source you are given an option to copy that db to the project and update the connection string path, if you do this VS creates a second connection in Database Explorer and names it for example "db.mdf1". A connection string is created in project Settings, which now connects to the project database file, not the first one created in Documents. So if you update the schema for the db pointed to by first connection, then project db is still unchanged, and running the Data Source wizard or Dataset wizard again will find no changes in tables.
  • So have a look at the connection string for the db which you are changing table definition for.
  • Also double check which connection string the Dataset uses, in this case both the mentioned connections will be available in the Data Source wizard.
There is also a third db file in this play, when a db is "copied to project" the project connection string (in project settings) is replacing the absolute db path with the "|DataDirectory|" path directive, which means during debugging and compiling the project db "template" is copied to build output directory and works as a runtime copy. It doesn't sound like you are changing this, though, that would be using external tools. You will see the "|DataDirectory|" in path from the settings connection string, but other places you will see the absolute path.
 
JohnH, what I did was when I added the dataset, instead of using the connection string I had used before, I created a new connection to the database in .\sqlexpress which is the directory that appears in the server explorer database. I think the problem is solved. Thanks a lot!
 

Latest posts

Back
Top