SQL Server Performance Forum – Threads Archive
Visual Studio and SQL ServerHi.
I am making a program in Microsoft Visual Studio and SQL Server. I am new at this, but have managed to write code that when entered in one of the forms in Visual Studio gets saved in the corresponding database table. But, when I ternimate the program, the information saved in the database tables gets lost and is no longer in the tables when I start the program again. Can someone please tell me what I have to do to make the data become permanently saved?
I am guessing that somehow your program is not committing the data to the database. The data is probably rolling back when you terminate your application. Use the keyword "COMMIT" at the end of your query and see if that helps. For more information, read about "implicit transactions" and "commit transaction" in SQL Server Books Online. – Tahsin
Me.MyTableTableAdapter.Update(Me.MyProjectDataSet.MyTable) This is the code I have used to save the data that is entered in the visual studio form, to the database-table. Where do I put the commit keyword????
It might also be (guessing here) that you’ve inserted the data into a dataset (which is just in memory) but have not sent it back to the actual database. If that is the case, you’d need to use the data adapter to update the database from the dataset.
Can someone please tell me what changes I have to make to my code to make the data become permanently saved???
How are you checking to see the contents of the database? Are you using your application or are you physically querying the database via the query tool in Management Studio?
Dim cstreng As String = "Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|prosjektoppgave.mdf;Integrated Security=true;User Instance=True"
Dim conKunde As New SqlClient.SqlConnection Dim cmdKunde As New SqlClient.SqlCommand
cmdKunde.Connection = conKunde
cmdKunde.CommandText = ctekst
Dim drKunde As SqlClient.SqlDataReader etc etc. This is some of the code I use to get information from the database.
I would suggest that you try to see whether or not you can physically query the database without using vbscript. After you feel that you have saved the data in your application, go and query the database yourself, without the use of the application. Do a "SELECT * FROM yourtablename" and see if the data is there. Also, I would remove the backslash "" after your |DataDiretory|. I don’t think it’s needed and I am not sure if it will cause errors in your connection string.
Saving Data:http://msdn2.microsoft.com/en-us/library/y2ad8t9c(VS.80).aspx Connecting to Data:
http://msdn2.microsoft.com/en-us/library/ms171932(VS.80).aspx Troubleshooting Data Access:
At the end of this section, there are many helpful links that will lead you to the right direction. Connection String Information: