Data not added to database on INSERT

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 String

sqlQuery = "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 Exception

MsgBox(ex.Message, MsgBoxStyle.OkOnly)

End Try

 

End 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)

Try

sqlConnection.Open()

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.OkOnly)

End Try

Dim sqlQuery As String

sqlQuery = "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>"

Loop

sqlConnection.Close()

'Slar ihop htmlmallen for foretagslistan med datan fran sqlfragan

Dim strCompanyListHtml As String

strCompanyListHtml = Me.companyListHtml.Replace("%CompanyList%", strCompanyList)

Me.WebBrowser.DocumentText = strCompanyListHtml

End Sub

When 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.



Answer this question

Data not added to database on INSERT