Can not save data into access through VB [duplicate] - vb.net

I am creating a library application in Visual Studio 2010 Professional and Access 2010. I bind the Access database to Visual Studio. When I fill out the fields and click submit I can see the new record in the DataGridView, but when I close the application the new record is not saved and I have to input the record again.
Can somebody help me to know why when I input the new record through the application the record is not saved in the database?

It is a very common situation. You have your database file (the MDB or ACCDB file) listed between your project items. If you click on this file and look at the properties window you will see a property called Copy to the output directory. If this property is set to Copy Always then every time you start a debug session the database file listed in your project items is copied by VS in the output directory (usually BIN\DEBUG). Of course this copy doesn't contain the records inserted in your last debug session and you think that your previous insert has failed.
Setting this property to Copy If Newer, the mentioned behavior will happen only if you change the database schema manually.
Setting this property to Copy Never, will let you manually copy the database file.

Related

Problem updating database source on visual studio

I created a database on access and added the data source to my visual studio vb project. However, I have recently added some new fields and tables on my database, how do I update it on my visual basic project without having to delete it and add it as a new data source which caused problems to my programs integrity ?
You can re-run the wizard and update the DataSet schema from the Data Sources window. I'm not in a position to test right now but, if memory serves, you can right-click the specific Data Source and select the appropriate item from the menu. If not, it would be a button on the toolbar in that window.
I don't think you need to change the data source, as the data source just refers to the database which has not changed. Ideally, the changes within the database should have reflected in the appropriate DataSet or DataCoulmn in your code. Can you post the code here, so that we can understand exactly what is going wrong?

Access is not showing the records I have entered through vb.net form

I am new in vb.net programming. Am facing a problem in database handling. Am using oledb to deal with database, which is MS Access in my project. I am dealing with queries at the time. Now the problem is that my queries are working well on vb form but are not affecting the actual database. For example, when am adding a record, it displays 'record added successfully', the message I have used for my conformation, but the actual database is not displaying the record I just entered and even got the above conformation message as well. I have checked query in sql editor too, its doing well. I have checked locals in vb debug mode, all are containing correct values.
Am not getting what's the reason behind that. Why it is displaying the success message but not modifying the actual database. Same is the case when am firing delete query, till now. I have not tried Update query yet.
Technology - Visual Basic.net with MS Access
Am using Access 2007 and Visual Studio 2013
Please Help by your suggestions
Do the controls on your form have the correct control source, i.e. the database table/query from and to which it should be reading and writing to?
Basically the problem was the gap between my understanding and .Net's working.
Here is the solution.
You can include database in two ways:
1.Either importing it directly to your project from the place, for example using drag and drop, or some other such method.
2.Or, by including it via using wizard.
But, the difference lies in connection string you use in your project, if you give absolute path of database, then you will directly see the alterations in database you have done using your application, even in testing and debugging mode via IDE.
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\xyz.accdb"
But if you are using connection string provide by wizard, for example,
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\xyz.accdb"
what the IDE will be doing is whenever you will be running project for debugging or testing, every time, it will copy the actual database, with its contents as well, in /bin/Debug folder. So, the changes you are performing will only be visible to that copy, not the actual file. So, if you want to verify with the database, like in our case, check the copy of database, which will be present in /bin/Debug folder. You will see the changes there. But, every time you run project for debugging, it will replace that copy with original one.
So, actually I was checking the original database file, not that copy, since the changes were only made to that copy. So that is why I was facing the above problem, not due to any programming fault.

Visual Basic data set not updating with mdb file

I have a .mdb (Access) file that I am using in my VB program. The program is basically just querying out data from the file. I prefer to update the database through access and then my vb program will just automatically be up to date upon saving the .mdb file. I have a data connection connected to the .mdb file and using the data set on my form. For some reason when I update the .mdb file, the program will not be updated with the new items....even if I right click and refresh the data connection and data set.
Is there a way I can fix this so that when I wont have to worry about deleting the connections and resaving in VB and creating an executable. I'd prefer my end result to just always work upon the .mdb file being updated.
When adding the connection and dataset there is a part that prompts you about it being a local file and if you want, you can have a copy saved to the projects directory. Clicking no will make sure that the local file will be used and not the copy in the project folder.

update script when comparing Visual studio database project to schema file

I have created a database schema file of a customers database. I want to compare this schema file to my database project i Visual Studio 2010 to be able to script the schema changes that needs to be done to the customer database in connection to the upgrade of our client program.
For filesize matters I want to use this schema file (23MB) rather than getting a full database copy (1352 MB when zipped) from the customer.
I have no problem comparing the Visual Studio project to the schema file (no error messages or warnings) but I find no means to get the resulting update script. The error I am getting when pressing "Refresh update script" is: "you cannot write updates to the target when you compare the specified types of schema models". All export options are disabled.
Of course I understand that I can't write updates to the database schema but that is not my intention - I want to run the update script on the database at our customers server.
Is there any way I can get out the update script?
Thanks!
I solved it by taking a few extra turns:
I created an empty database on our local sql-server.
I compared the schema from our customers database with the empty database as target in Visual Studio and updated the empty database with the change script created by Visual Studio.
I compared the updated database with the new database schema from TFS.
The new change script I got from Visual Studio was deployed to our customers database.
Hope this helps someone, at least I learnt from it (and will hopefully remember this until the next release).

VB.NET - Local database (SQL Server Compact 3.5 database) data gone after update?

I have created an application in VB.NET (using Microsoft Visual Basic 2010 Express) with a local database (SQL Server Compact 3.5 database) to store data.
I have installed this on the users computer, and added a "search online for updates" functionallity (which can be selected when publishing)
Now i have noticed, that sometimes when i upload a new version, the data from the database gets cleared. (possibly when i opened the dtb while developing)
This is offcourse not how i want the system to behave, and the data should always remain on the users computer.
In 'Application Files' the database file (*.sdf) is currently set to 'Data File (Auto)', but i'm unsure of the exact way this works.
Could anyone help me to understand how all of this works, and tell me how i can be sure that the data in the users database will remain, even after an update?
If there is no solution to ensure this, is there a way to safely backup the data and reload it?
Thanks in advance!!
Basically, the click one install overwrites everything in the program folder that is included in your publish. So if you include the .sdf then it will overwrite it when the installer is executed. What you need to do is select "exclude" on the sdf instead. This will keep the database in its previous state.
So my recommendation would be to have 2 different publishes. One that you create that contains the .sdf which is only used on first time installation, and then in all the update ones you exclude it.
To perform updates on your tables you would have to write the SQL for it in your software. Basically do a check on all tables to see that they have the proper setup on startup. If they don't then you add the missing columns.
Hope this helps.