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 7043773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:19:49+00:00 2026-05-28T02:19:49+00:00

I’m currently working on a project that involves a CSV file. I initially was

  • 0

I’m currently working on a project that involves a CSV file. I initially was using Microsoft.Jet.OLEDB.4.0 to extract everything. However, there are large numbers that sometimes don’t make it over and are “blanked” out.

So, after doing some research, I was able to find an example where I could stuff everything into a list. For example:

Dim lstExample As New List(Of String)().  

From here I could use a SteamReader to grab the csv file and store it. Since the first 3 lines are garbage, I’m skipping those and reading all the rest of the lines along with about 30 columns of comma delimited data.

My problem now is that I’m unable to get the lstExample into either a dataset or datatable. I even manually created a list and it still errors out.

The error occurs on this line:

dataRow(i) = itemProperties(i).GetValue(item, Nothing) saying "Parameter count mismatch."

Any ideas to get a List into dataset/datatable?

   Public Shared Sub ManualReadCSVFile(ByVal strFilePath As String)
    Dim lstExample As New List(Of String)()

    Using reader = New StreamReader("c:\SFTP_Target\ATL-536437.csv")
        For i As Integer = 0 To 2
            reader.ReadLine()
        Next

        While Not reader.EndOfStream
            Dim line = reader.ReadLine()
            Dim values = line.Split(",")

            lstExample.Add(values(0))

        End While

        reader.Dispose()
    End Using

    'Dim list As New List(Of String)(New String() {"nile", _
    '    "amazon", _
    '    "yangtze", _
    '    "mississippi", _
    '    "yellow"})

    Dim dsTest As New DataSet
    dsTest = CreateDataSet(lstExample)
    'dsTest = CreateDataset(list)

End Sub

Public Shared Function CreateDataSet(Of T)(ByVal list As List(Of T)) As DataSet
    'list is nothing or has nothing, return nothing (or add exception handling)
    If list Is Nothing OrElse list.Count = 0 Then
        Return Nothing
    End If

    'get the type of the first obj in the list
    Dim obj = list(0).[GetType]()

    'now grab all properties
    Dim properties = obj.GetProperties()

    'make sure the obj has properties, return nothing (or add exception handling)
    If properties.Length = 0 Then
        Return Nothing
    End If

    'it does so create the dataset and table
    Dim dataSet = New DataSet()
    Dim dataTable = New DataTable()

    'now build the columns from the properties
    Dim columns = New DataColumn(properties.Length - 1) {}
    For i As Integer = 0 To properties.Length - 1
        columns(i) = New DataColumn(properties(i).Name, properties(i).PropertyType)
    Next

    'add columns to table
    dataTable.Columns.AddRange(columns)

    'now add the list values to the table
    For Each item In list
        'For Each item As T In list
        'create a new row from table
        Dim dataRow = dataTable.NewRow()

        'now we have to iterate thru each property of the item and retrieve it's value for the corresponding row's cell
        Dim itemProperties = item.[GetType]().GetProperties()

        For i As Integer = 0 To itemProperties.Length - 1
            dataRow(i) = itemProperties(i).GetValue(item, Nothing)
        Next

        'now add the populated row to the table
        dataTable.Rows.Add(dataRow)
    Next

    'add table to dataset
    dataSet.Tables.Add(dataTable)

    'return dataset
    Return dataSet
End Function
  • 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-05-28T02:19:49+00:00Added an answer on May 28, 2026 at 2:19 am

    if you are simply trying to parse a csv file into .net objects try http://www.filehelpers.com. it’s a simple way to parse csv files into POCOs or datatables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from

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.