Hi!
It seems as when I run a INSERT query the information get added to the database, but when I close the application down and start it back up the information is gone. I have two pieces of code.
The code to insert data to the database looks like this:
Using
sqlConnection As New Data.SqlClient.SqlConnection(BOCompany.My.Settings.BOCompanyConnectionString) Dim sqlQuery As StringsqlQuery =
"INSERT INTO CompanyTable WITH (TABLOCK) "sqlQuery +=
"(name, adress, postalcode, city, telephone, fax, website, contact, description) "sqlQuery +=
"VALUES("sqlQuery +=
"'" + NameTextBox.Text + "', "sqlQuery +=
"'" + AdressTextBox.Text + "', "sqlQuery +=
"'" + PostalcodeTextBox.Text + "', "sqlQuery +=
"'" + CityTextBox.Text + "', "sqlQuery +=
"'" + TelephoneTextBox.Text + "', "sqlQuery +=
"'" + FaxTextBox.Text + "', "sqlQuery +=
"'" + WebsiteTextBox.Text + "', "sqlQuery +=
"'" + ContactTextBox.Text + "', "sqlQuery +=
"'" + DescriptionTextBox.Text + "')" Try Dim sqlCommand As New Data.SqlClient.SqlCommand(sqlQuery, sqlConnection)sqlCommand.Connection.Open()
sqlCommand.ExecuteNonQuery()
Catch ex As ExceptionMsgBox(ex.Message, MsgBoxStyle.OkOnly)
End TryEnd Using
Form1.CompanyListRefresh()
And the code to list the inserted data looks like this:
Public
Sub CompanyListRefresh() 'Provar att oppna kopplingen till databasen Dim sqlConnection As New SqlClient.SqlConnection(BOCompany.My.Settings.BOCompanyConnectionString) TrysqlConnection.Open()
Catch ex As ExceptionMsgBox(ex.Message, MsgBoxStyle.OkOnly)
End Try Dim sqlQuery As StringsqlQuery =
"SELECT * FROM CompanyTable ORDER BY 'id' DESC;" Dim sqlCommand As New SqlClient.SqlCommand(sqlQuery, sqlConnection) Dim sqlDataReader = sqlCommand.ExecuteReader() 'Laser data returnerad fran queryn och formatterar den som html Dim strCompanyList As New String("") Do While sqlDataReader.read()strCompanyList +=
"<div class='Company'>"strCompanyList +=
"<h1>" & sqlDataReader(1) & "</h1>"strCompanyList +=
"</div>" LoopsqlConnection.Close()
'Slar ihop htmlmallen for foretagslistan med datan fran sqlfragan Dim strCompanyListHtml As StringstrCompanyListHtml =
Me.companyListHtml.Replace("%CompanyList%", strCompanyList) Me.WebBrowser.DocumentText = strCompanyListHtml End SubWhen CompanyListRefresh is called the newly added data is presented as it should be. But, as I said, when the apllication is closed and restarted again it's gone. Have I forgotten anything I get no errors and no exeptions whatsoever.
I have willfully chosen not to use DataSets and TableAdapters, so please don't suggest that I use those. This is meant for learning, not production.
Thanks in advance.

Data not added to database on INSERT
mcrfanatic
Please read the following:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=139410&SiteID=1
cj74