Right now I have a datagrid (dgvResults) that shows results of all the records in the table CS_Comm. When I make a change to a select record in an editable cell and click the 'Save' button, I get the error 'System.InvalidOperationException' {"The ConnectionString property has not been initialized."} and points to _sdaAdapter.Update(_dt).
Any idea why this is happening?
Code:Dim _sdaAdapter As SqlDataAdapter Dim _dt As DataTable Private Sub Commissions_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.Icon = My.Resources.AppIcon LoadData() End Sub Sub LoadData() dgvResults.DataSource = Nothing dgvResults.Rows.Clear() Try Dim connection As New SqlConnection Dim sqlCommand As New SqlCommand connection.ConnectionString = GetConnectionString() connection.Open() sqlCommand.CommandText = "SELECT * FROM CS_Comm ORDER BY CS_Comm_ID desc" sqlCommand.Connection = connection sqlCommand.Parameters.Clear() _sdaAdapter = New SqlDataAdapter(sqlCommand) _dt = New DataTable _sdaAdapter.Fill(_dt) Dim sqlCB As New SqlCommandBuilder(_sdaAdapter) connection.Close() connection.Dispose() dgvResults.DataSource = _dt dgvResults.Columns(0).ReadOnly = True dgvResults.Columns(1).ReadOnly = True dgvResults.Columns(10).ReadOnly = True dgvResults.Columns(11).ReadOnly = True dgvResults.Columns(12).ReadOnly = True dgvResults.Columns(13).ReadOnly = True tslWarning.Text = "Records: " & dgvResults.RowCount - 1 Catch ex As Exception tslWarning.Text = "ERROR: " & ex.ToString End Try End Sub Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click _sdaAdapter.Update(_dt) End Sub




Reply With Quote