Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8345055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:33:56+00:00 2026-06-09T06:33:56+00:00

i am trying to write an mdb to CVS converter with vb.net. i want

  • 0

i am trying to write an mdb to CVS converter with vb.net.
i want to get the columns header names using the oledbdata reader and here is my code so far

 Public Cheadernames As Array
    Public firstRead As Boolean = False
    Public columnCount

    Dim connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strfilename
    Dim queryString = "SELECT * FROM products"
    Dim connection As New OleDbConnection(connectionstring)
    Dim command As New OleDbCommand(queryString, connection)
    connection.Open()
    Dim reader As OleDbDataReader = command.ExecuteReader()
    While reader.Read
        If firstRead Then
            columnCount = reader.FieldCount()
            firstRead = False
            For i = 0 To columnCount - 1
                Cheadernames(i) = reader.GetName(i) ' i am getting an error with this line
                Console.WriteLine(Cheadernames(i))
            Next
        End If

so i am trying to put all column headers names in an array but the commented line gives me this error “Object variable or With block variable not set”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:33:57+00:00Added an answer on June 9, 2026 at 6:33 am

    Your Cheadernames variable is an empty array, with no elements and no type. That’s just wrong: you should almost never declare a variable or method parameter “As Array”. Instead, you want something like this:

    Private HeaderHames() As String
    Private firstRead As Boolean = True
    Private columnCount As Integer
    
    Dim connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strfilename
    Dim queryString = "SELECT * FROM products"
    Using connection As New OleDbConnection(connectionstring), _ 
          command As New OleDbCommand(queryString, connection)
    
        connection.Open()
        Using reader As OleDbDataReader = command.ExecuteReader()
            While reader.Read
                If firstRead Then
                    columnCount = reader.FieldCount()
                    HeaderNames = New String(columnCount-1)
                    firstRead = False
                    For i = 0 To columnCount - 1
                        HeaderNames(i) = reader.GetName(i) 
                        Console.WriteLine(HeaderNames(i))
                    Next
                End If
                '...
             End While
         End Using
     End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write a windows speech recognition macro. Written using XML and scripting language
Trying to write Unit test for Silverlight 4.0 using Moq 4.0.10531.7 public delegate void
I'm writing, or trying to write, Baby's First MDB on WebSphere 7. I have
I am having a little bit of trouble trying to write to a .mdb
I'm trying write a program that takes a list of names, sorts those names,
Possible Duplicate: Access GET variables with PHP + .htaccess I am trying write a
trying to write to work book and change the cell colour using... CellStyle style
Trying to write dynamic queries using the LINQ provider for NHibernate, but I am
Trying to write such function. It must divide text into multiple columns and the
I'm trying write a Ruby script that checks if user credentials are valid using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.