I'm filling a DataTable with a Stored Procedure and attempting to send the results to an SQL Table. I'm getting the error:
A first chance exception of type 'System.InvalidCastException' occurred in Project Manager.exe
I've tried using 2 or 3 different methods to do this, but I really am out of ideas. I'm not sure I'm using the TableAdapter correctly here:
Code:Dim StartDate As Date = Me.DateTimePicker1.Text Dim EndDate As Date = Me.DateTimePicker2.Text Dim Detail As String = "detail" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim TableAdapter As New MANEXONTIMEDataSet2TableAdapters.QkViewCustomerOntimeTableAdapter TableAdapter.GetData(dateStart:=StartDate, dateEnd:=EndDate, type:=Detail) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'copy the contents of the DataTable to the SQL table OnTimeChart Dim sqCon As New SqlClient.SqlConnection("Server=QCG13\SQLSTANDARD;Database=QCGMAIN; Trusted_Connection=True;") sqCon.Open() Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(sqCon) bulkCopy.DestinationTableName = "OnTimeChart" Try ' Write from the source to the destination. bulkCopy.WriteToServer(TableAdapter) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Using sqCon.Close()




Reply With Quote
