Everything seems to imports ok until i look at the data in more detail, this is when I notice its imported the data but in the wrong order.
for some reason when I look at the db table all records are in the wrong order, and strangely enough it seems to be a different order every time I import things.
Is there a way to force the routine to import the data in the same order as the it is in the excel file?, because at the minute it seems to have a mind of its own
any help / advice will be appreciated as always
My code is below:
Public Function ReadExcelFile(ByVal sFileName As String) As Boolean Dim oSQL As New clsSQLHolder Dim excelCon As String Dim excelstrCon As OleDb.OleDbConnection Dim reader As OleDb.OleDbDataReader Dim cmd As New OleDb.OleDbCommand Try Try excelCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sFileName + ";Extended Properties=""Excel 8.0;HDR=YES;IMEX=1""" excelstrCon = New OleDb.OleDbConnection(excelCon) excelstrCon.Open() 'Create objects and get data cmd = New OleDb.OleDbCommand("SELECT * FROM [Sheet1$]", excelstrCon) reader = cmd.ExecuteReader 'open the destination data Dim dbCon As SqlConnection = New SqlConnection(sConnectionString) dbCon.Open() Dim bulkCopy As SqlBulkCopy = New SqlBulkCopy(dbCon) bulkCopy.DestinationTableName = "tblFocusTemp" bulkCopy.WriteToServer(reader) Catch ex As Exception Throw New Exception(ex.Message, ex) End Try Finally reader.Close() excelstrCon.Close() End Try End Function
This post has been edited by AdamSpeight2008: 29 March 2012 - 04:48 AM
Reason for edit:: Please use the CODE tags