I have had this headache for a few days now. Thought I had sorted it but haven't.
I have copied worksheets from an excel workbook into a dataset, with each a datatable for each worksheet.
I then use a DataGridView to Display and edit the datatable.
DataGridview.DataSource = MydataSet.DataTable(0) sort thing.
But for some reason I just cant figure out how to write the datatable back to the excel worksheet.
I have this but Im probably barking up the wrong tree.
This headache just wont go away. Even an explaination why this dont work would help.Code:Public Function WriteDataTable(ByVal SheetName As String, ByVal ColumnName As String) As Boolean Dim Sql As String = "UPDATE [" & SheetName & "$] SET " & ColumnName & " = ?" Debug.WriteLine(Sql) Try Dim MyAdapter As OleDbDataAdapter = New OleDbDataAdapter(Sql, MyConnection) MyConnection.Open() MyAdapter.Update(MyDataSet, SheetName) MyConnection.Close() Return True Catch ex As Exception MyConnection.Close() Debug.WriteLine(ex.ToString) Return Nothing End Try End Function




Reply With Quote