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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:45:58+00:00 2026-05-14T05:45:58+00:00

I have to do an export from DB to CSV. ( .NET 2 )

  • 0

I have to do an export from DB to CSV. (.NET 2)

field; fileld; field... etc

Have 3 types of fields: Alpha, Numeric and Bool respresented as "alphaValue",intValue and True/False.

I try to encapsulate this in a fields collection, in order to export if alpha then set “”, if Bool=>True/False if numeric let as is.

and try to build a CsvField class:

  Public Structure?Class CsvField(Of T As ???)

  End Structure

  Enum FieldType
    Alpha
    Bool
    Numeric
  End Enum

possibile usage:

myCollection.Add(new CsvField(DateTime.Now, FileType.Alpha))
myCollection.Add(new CsvField(myInt, FileType.Numeric))

any suggestions welcomed.

  • 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-14T05:45:59+00:00Added an answer on May 14, 2026 at 5:45 am

    No generics needed. Simply use inheritance:

    ' abstract base class; you could possibly declare it as an interface instead: '
    MustInherit Class CsvField
        Public MustOverride Function Export() As String
    End Class
    
    
    ' specialized class for alpha-numeric fields: '
    Class AlphaCsvField : Inherits CsvField
        ...
        Public Overrides Function Export() As String
            Return String.Format("""{0}""", value)
        End Function
    
        Private value As String
    End Class
    
    
    ' specialized class for bool fields '
    Class BoolCsvField : Inherits CsvField
        ...
        Public Overrides Function Export() As String
            If value = True Then
                Return "True"
            Else
                Return "False"
            End If
        End Function
    
        Private value As Boolean
    End Class
    
    ...
    

    The code example assumes that value stores the actual value of a field. I hope this example is sufficiently clear. Make your fields collection one for type base class type, e.g. List(Of CsvField). It can then contain objects of all derived types, too.


    Btw., note how, when using polymorphism, you might be able to get rid of the FieldType enumeration completely and all If / Select Case constructs that decide on what to do depending on the field type. If you still need to do that, you could replace:

    If someCsvField.FieldType = Alpha Then ...
    

    with

    If TypeOf someCsvField Is AlphaCsvField Then ...
    

    However, you should generally be able to move such logic into the derived classes and get rid of the If statements by overriding methods. This is the whole point of the above example.


    P.S.: In case you’re wondering how you create your CsvField objects without checking explicitly on the type. One way is to use factory methods and method overloading:

    MustInherit Class CsvField
    
        Public Shared Function Create(value As String) As CsvField
            Return New AlphaCsvField(value)
        End 
    
        Public Shared Function Create(value As Boolean) As CsvField
            Return New BoolCsvField(value)
        End 
    
        ...
    
        ' as in the above code example '
        Public MustOverride Function Export() As String
    
    End Class
    

    For example, CsvField.Create(False) would create a BoolCsvField “disguised” as a CsvField, so that you can put it inside your List(Of CsvField) or whatever collection you have.

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

Sidebar

Related Questions

I have this code which export data from GridView to csv. It works with
i need to export data from a table to a csv. i have the
I have a CSV export script (enrdata_arch.php) which calls information from an existing database
I have some data to export from DB and save as CSV file, and
I have a PHP script that produces a .CSV export file from a MySQL
I have a script to export data from MYSQL to a CSV file. the
I have a requirement to export some data from a table (not all fields
I'm trying to export data from SQL Server into CSV format. I have a
I need to export data from Sql Server 2008 to Excel/CSV file. I have
I have been thinking of a way to export data from SQL to Excel.

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.