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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:45:17+00:00 2026-06-03T18:45:17+00:00

I want to read from my response data reader object the column name and

  • 0

I want to read from my response data reader object the column name and type, because i need it to instantiate some objects. I came out with this :

using (db.sqlConnection) {
    db.sqlConnection.Open();
    using (var cmd = new SqlCommand("areaGetStreetTypes", db.sqlConnection)) {
        cmd.CommandType = CommandType.StoredProcedure;
        using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.KeyInfo)) {
            DataTable dt = dr.GetSchemaTable();
            foreach (DataRow myField in dt.Rows) {
                foreach (DataColumn coloana in dt.Columns) {
                    string c1 = coloana.ColumnName;  //column name ???
                    string c2 = coloana.GetType().ToString(); //column type ??
                    Console.WriteLine(c1 + "  " + c2);
                }
            }
        }
    }
}

but is not working. For each column returns i want to print (for starter) something like :

id_someID int32    
name string    
surname string     
ssn string

what is wrong in my code?

  • 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-03T18:45:19+00:00Added an answer on June 3, 2026 at 6:45 pm

    I think you actually want somthing like

    DataTable dt = dr.GetSchemaTable();
    foreach (DataRow myField in dt.Rows) 
    {
        var name = myField["ColumnName"];
        var type = myField["DataTypeName"];
        Console.WriteLine("{0} {1}", name, type);
    }                     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read data from a YAML file but I need the order
I want call a url and get the response data from the url from
Here I want to make some modificatins for my setting. I want response from
Hello I want to post some data from silverlight to a website. I found
I want to read json response as name and value pairs in my JQuery
I want to read from stdin five numbers entered as follows: 3, 4, 5,
i want to read from a text file in C#. But I want all
I want to read lines from a file into a Set or List. Is
i want to read characters from the console and print them one after another
I want to read actionmessages from the property file in struts2 and at the

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.