I hv an excel file which got 3 columns and no header also.
I need to read my 3rd column,anyway my program will read the third column and since i dont have a header, reading the excel data starting only from the second row and program treating the first row as header. Appreciate if somebody can help me to modify the program to read the data from the from the first row itself.
here is my coding
For xfile As Integer = 0 To TempDir.GetFiles("*.xls").Length - 1 ================ 'reading the excel file from tem folder one by one
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & TempDir.GetFiles("*.xls")(xfile).FullName & ";Extended Properties=Excel 8.0"
conxls = New OleDb.OleDbConnection(ConnectionString)
''get sheet name
Dim oExcel As New Excel.Application
Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim strsheetname As String
Dim strSQL As String
oExcel.Visible = False : oExcel.DisplayAlerts = False
oBooks = oExcel.Workbooks
File.Copy(TempDir.GetFiles("*.xls")(xfile).FullName, "c:\" & fname) =========getting the sheetnam
oBooks.Open("c:\" & fname)
oBook = oBooks.Item(1)
oSheet = oExcel.Sheets.Item(1)
strsheetname = oSheet.Name
oExcel = Nothing
strSQL = "Select * from [ " & strsheetname & "$]"
Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from [" + strsheetname + "$]", conxls) ====getting the sheet name
Dim dt As New DataTable
Dim dr As DataRow
For Each dr In dt.Rows
strLine = CType(dr(2), String) ==========================I need read data from my third column only
SQLcmd.CommandText = "If not Exists(Select * from applesource Where SerialNo ='" & CType(dr(2), String) & "') " & _
" Insert into applesource values ('" & CType(dr(2), String) & "')" ===========inserting data to sql server table
SQLcmd.CommandType = CommandType.Text
RowsAffected = SQLcmd.ExecuteNonQuery()
Pls help me to change my program to read the first row as the current program is treating the first row as header and reading from second row only. Pls help. I need it very urgent............