Hi I have a problem with this code. I'm trying to save a values in the database.. When I click the save button the table is being updated and showing the new values I entered. But the problem is it is not actually saved in the database, when I re-run my program the new values are gone. Please help! Thanks!
Private Sub DataGridView1_Load()
da = New SqlClient.SqlDataAdapter("SELECT * FROM tblEmployee", con)
da.Fill(dt)
DataGridView1.DataSource = dt
DataGridView1.Refresh()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
da.InsertCommand = New SqlClient.SqlCommand("INSERT INTO tblEmployee([Last Name], [First Name], [Middle Initial], [Age], [Username], [Password])" & _
"VALUES('" & txtLastName.Text & "', '" & txtFirstName.Text & "', '" & txtMiddleInitial.Text & "', " & txtAge.Text & ", '" & txtUsername.Text & "', '" & txtPassword.Text & "')", con)
da.InsertCommand.ExecuteNonQuery()
da.Update(dt)
dt.Clear()
Call DataGridView1_Load()
MsgBox("New user has been saved.", MsgBoxStyle.Information, "Sales and Inventory")
End Sub