Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27159

VS 2010 Getting column names as F1, F2, etc. instead of the column name.

$
0
0
Hello to all.

I have this piece of code, which writes the content of a worsheet into a text file. In spite i have declared HDR=Yes i'm stil getting column names as F1, F2, etc.

Can someone please explain me what am i doing wrong?

Thanks in advance for any kind help.

Octavio

Code:

Dim CurDir As String = Environment.CurrentDirectory
        Dim FichTexto As New StreamWriter(CurDir & "\" & Format(Now, "yyyyMMdd") & Format(Now, "ss") & ".PS2")
        Dim BDados As String = "\\Boxus\Geral\Dados\UTLT.accdb"
        Dim cbExcel As New OleDbConnectionStringBuilder With {.DataSource = ExcelFich, .Provider = "Microsoft.ACE.OLEDB.12.0"}
        cbExcel.Add("Extended Properties", "Excel 12.0; HDR=Yes")
        Dim dt As New DataTable
Using cnExcel As New OleDbConnection With {.ConnectionString = cbExcel.ConnectionString}
            cnExcel.Open()
            Dim cmdExcel As OleDbCommand = New OleDbCommand("SELECT * from [Sheet1$]", cnExcel)
            dt.Load(cmdExcel.ExecuteReader)
            If dt.Rows.Count > 0 Then
                For Each linha As DataRow In dt.Rows
                  FichTexto.Write(linha("Contador")) 'Here i receive the message that this column does not exist (and it does). If i use "F1" as column name the data comes out.                
                FichTexto.Write(vbCrLf)
                Next
                FichTexto.Close()
            Else
                MsgBox("O ficheiro de input não tem dados")
                Return
            End If
        End Using


Viewing all articles
Browse latest Browse all 27159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>