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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:03:17+00:00 2026-06-09T16:03:17+00:00

I have a SqlDataReader reader, where I don’t know the data structure in advance,

  • 0

I have a SqlDataReader reader, where I don’t know the data structure in advance, i.e. the number of columns is unkown. I’d like to put the table in csv file.
I retrieve the columns from

System.Data.DataTable dt = reader.GetSchemaTable();

So I have them in dt.Columns() after it. Then, I want to do something like this:

while (reader.Read())
{
    writer.WriteLine(string.Join(";",ListWithRowContent))
}

However, I have it hard to put the content of a row into ListWithRowContent list with something like linq .Select , but “reader” object can’t be queried.
Question: how to do it (please no for loop!)?

  • 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-09T16:03:18+00:00Added an answer on June 9, 2026 at 4:03 pm

    Assuming, that reader is positioned on any record:

    var values = new Object[reader.FieldCount];
    
    reader.GetValues(values);
    
    writer.WriteLine(string.Join(";", values.Select(v => v.ToString())));
    

    or more convenient way (FW 4.0 or higher):

    var values = new Object[reader.FieldCount];
    
    reader.GetValues(values);
    
    writer.WriteLine(string.Join(";", values));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data in a database table, Columns : Date, Hour(from 1
I have this piece of code in c#: private static void _constructRow(SqlDataReader reader, system.IO.StreamWriter
I have a sqldatareader spitting out SQL data on a page on page load
I have a base class that contains a SqlDataReader which gets the data using
I have the following code: SqlDataReader reader = getAddressQuery.sqlReader; while (reader.Read()) { foreach (Object
I have a simple method: public static T GetValue<T>(SqlDataReader reader, int columnIndex, T defaultValue
We have built an internal tool that generates the whole data access, each table
I have a SqlDataReader and need to read a varbinary(max) column from it using
I have a question about SqlDataReader: Is there some way to modificated the values
I have a small C# function that takes any generic SQLDataReader and converts it

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.