Code to update Data Adapter
I have a forum where I fill a datagrid with all the data from a table. The table name is pulled from a text box like this (button control):
Code:
Dim cnn As SqlClient.SqlConnection = _
New SqlClient.SqlConnection( _
"Data Source=ServerName;" & _
"Initial Catalog=DataBaseName;" & _
"User ID=SQLUser;password=password")
Dim strTableName As String = txtTableName.Text
Dim cmd As New SqlClient.SqlCommand
Dim da As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
Try
da.Fill(ds, strTableName)
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, _
MsgBoxStyle.OKCancel, "Fill Grid Error")
End Try
Now I would like to add a second button control to save any changes made in the grid. I thought this would do the trick but I am getting a table mapping error. What is missing?
Code:
Dim cnn As SqlClient.SqlConnection = _
New SqlClient.SqlConnection( _
"Data Source=ServerName;" & _
"Initial Catalog=DataBaseName;" & _
"User ID=SQLUser;password=password")
Dim strTableName As String = txtTableName.Text
Dim cmd As New SqlClient.SqlCommand
Dim da As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
Try
da.Update(ds, strTableName)
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, _
MsgBoxStyle.OKCancel, "Save Udpates")
End Try