hi.... i have a code for retrieve each data from excel to update dbf file. i use Microsoft.Office.Interop.Excel for read the data each range of column.
now i want to change the connection excel using oledb..
how can i retrieve data of each column and set it into a variable?
here is my code for Microsoft.Office.Interop.Excel.
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(xlsName)
xlWorkSheet = xlWorkBook.Worksheets("sheet1")
xlRange = xlWorkSheet.UsedRange
endrow = xlRange.Rows.Count
For rCnt = 3 To endrow
Empno = xlRange.Cells(rCnt, 1).Value
totalhrs = xlRange.Cells(rCnt, 3).Value
latehr = xlRange.Cells(rCnt, 4).Value
Next
xlWorkBook.Close()
xlApp.Quit()
this is my oledb connection. after the connection,i really dont have an idea what should i do to get the data. please help me...i hope someone in codeproject can help me.
Dim xlsConnect As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Try
If (Path.GetExtension(xlsName) = ".xls") Then
xlsConnect = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & xlsName & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2""")
ElseIf (Path.GetExtension(xlsName) = ".xlsx") Then
xlsConnect = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & xlsName & ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';")
End If
MyCommand = New System.Data.OleDb.OleDbDataAdapter("Select * from [Sheet1$]", xlsConnect)
xlsConnect.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try