I have a WinForms app and have a situation where I fill a Datagridview with info and then the connection to the Database is closed. It could some time later that the person needs to edit a cell in the Datagridview.
This code works with the connection already open. But, if it is not open, what do I need to add to this code to get the Update to work? The connection to the sqlserver needs to be re-established. Or, does the connection need to be Open at all times?
Try
Dim cb As New Data.SqlClient.SqlCommandBuilder(DataAdapter)
DataAdapter.Update(Dataset, "Memo")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
End Try
I am trying to follow the best practice of closing the connection when not needed.