Update SQL from DataGridView - IndexOutOfRangeException "Cannot find table (0)' error
I am trying to save changes (UPDATE) from a DataGridView to the SQL Table it was pulled from.
It pulls the data fine, I can make my adjustments, but when I click my button to update I get a
"IndexOutOfRangeException "Cannot find table (0)' error" error.
I am just wanting to update the changes I made to the data I pulled.
Any help is greatly appreciated.
Data is pulled in a button click sub before this one with the SQLConnection declared in Private in the Public Class form.
I am trying to save changes (UPDATE) from a DataGridView to the SQL Table it was pulled from.
It pulls the data fine, I can make my adjustments, but when I click my button to update I get a
"IndexOutOfRangeException "Cannot find table (0)' error" error.
I am just wanting to update the changes I made to the data I pulled.
Any help is greatly appreciated.
VB.NET:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim daSWC2 As New SqlDataAdapter
Dim SQLcmdBuilder2 As New SqlCommandBuilder(daSWC2)
Dim ds2 as New DataSet
DataGridView1.Datasource = ds2.Tables(0) 'ERROR is HERE
daSWC2.Update(DataGridView1.DataSource)
MessageBox.Show("Items have been Updated")
DataGridView1.DataSource = Nothing
DataGridView1.Rows.Clear()
DataGridView1.Columns.Clear()
End Sub