I am exporting data from a spreadsheet worksheet range into a datatable (dtpHExportDataTable). When I call ShowResult(dtpHExportDataTable), the grid form displays the correct datatable information (headers and rows of data). Likewise, when I call ShowResult(resultsDataTable) the grid form displays the correct datatable information (the database table rows including the updated rows)
Using cnSQL1 As New SqlConnection
cnSQL1.ConnectionString = cnString
Using adapter1 = New SqlDataAdapter("SELECT SampleNo, Results, Complete_Date, Dex_Row_Id " _
& "FROM LIMS.dbo.Analytical_Sample_Log_ResultsInfo", cnSQL1)
Dim builder1 As New SqlCommandBuilder(adapter1)
adapter1.UpdateCommand = builder1.GetUpdateCommand()
Using New SqlCommandBuilder(adapter1)
adapter1.Fill(resultsDataTable)
resultsDataTable.PrimaryKey = New DataColumn() {resultsDataTable.Columns("Dex_Row_Id")}
dtpHExportDataTable = resultsDataTable.Clone()
‘not sure if needed, just trying to make sure datatypes are correct
dtpHExportDataTable.Columns("SampleNo").DataType = System.Type.GetType("System.Int32")
dtpHExportDataTable.Columns("Results").DataType = System.Type.GetType("System.String")
dtpHExportDataTable.Columns("Complete_Date").DataType = System.Type.GetType("System.DateTime")
dtpHExportDataTable.Columns("Dex_Row_Id").DataType = System.Type.GetType("System.Int32")
' Create the exporter that obtains data from the specified range,
' skips header row if required and populates the specified data table.
Dim exporter As DataTableExporter = workSheet.CreateDataTableExporter(range, dtpHExportDataTable, rangeHasHeaders)
AddHandler exporter.CellValueConversionError, AddressOf exporter_CellValueConversionError
' Specify exporter options.
exporter.Options.ConvertEmptyCells = True
exporter.Options.DefaultCellValueToColumnTypeConverter.EmptyCellValue = 0
' Perform the export.
exporter.Export()
ShowResult(dtpHExportDataTable) ‘grid form shows expected information
For index = 1 To dtpHExportDataTable.Rows.Count - 1
dtpHExportDataTable.Rows(index).SetModified()
Next
resultsDataTable.Merge(dtpHExportDataTable)
ShowResult(resultsDataTable) ‘grid form shows expected information
Try
adapter1.Update(resultsDataTable)
Catch ex As Exception
MsgBox("Update failed")
End Try
End Using
End Using
End Using
My tableadapter Query Builder, Update command text is “UPDATE Analytical_Sample_Log_ResultsInfo SET SampleNo = @SampleNo, Results = @Results, Complete_Date = @Complete_Date WHERE (Dex_Row_Id = @Original_Dex_Row_Id)
In essence, the datatables populate correctly; however, the tableadapter is not updating the sql database table even though an exception is not thrown.