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

  • Home
  • SEARCH
  • 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 8770867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:38:44+00:00 2026-06-13T17:38:44+00:00

I have designed a Form in VS 2008. I have a database table containing

  • 0

I have designed a Form in VS 2008. I have a database table containing the following fields:

Fname (char)
MailFrom (char)
MailTo (char)
Subject (char)
Body (char)
MailID (int)

Now I to extract the data from the database and display it on the form in their respective fields.

my code behind is:

SqlConnection conn = new SqlConnection(
        "Data Source=PTZ1\\SQLEXPRESS;Initial Catalog = test; Integrated Security=SSPI;User ID=sa; Password=sa@; Trusted_Connection=True;");

    SqlDataReader rdr = null;

    try
    {
        // Open the connection
        conn.Open();

        // Pass the connection to a command object
        SqlCommand cmd = new SqlCommand("select * from testing", conn);

        //
        // Use the connection
        //

        // get query results
        rdr = cmd.ExecuteReader();

        while (rdr.Read())
        {
            Console.WriteLine(rdr[]);
        }
    }
    finally
    {
        // close the reader
        if (rdr != null)
        {
            rdr.Close();
        }

        // Close the connection
        if (conn != null)
        {
            conn.Close();
        }
    }

How do I store and display the data on the console

  • 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-13T17:38:45+00:00Added an answer on June 13, 2026 at 5:38 pm

    You can store the result of the query in memory using DataTable for the storage and displaying of that data on Console:

    // Create a String to hold the query.
    string query = "SELECT * FROM testing";
    
    // Create a SqlCommand object and pass the constructor the connection string and the query string.
    SqlCommand cmd = new SqlCommand(query, conn);
    
    // Use the above SqlCommand object to create a SqlDataReader object.
    SqlDataReader rdr = queryCommand.ExecuteReader();
    
    // Create a DataTable object to hold all the data returned by the query.
    DataTable dataTable = new DataTable();
    
    // Use the DataTable.Load(SqlDataReader) function to put the results of the query into a DataTable.
    dataTable.Load(rdr);
    

    OR

    1. Definite your custom class, e.g. ‘Email` this way:

      class Email
      {
          public string Fname { get; set; }
          public string MailFrom { get; set; }
          public string MailTo { get; set; }
          public string Subject { get; set; }
          public string Body { get; set; }
          public int MailID { get; set; }    
      }
      
    2. Read the values in your custom class collection:

      List<Email> list = new List<Email>();
      
      while (rdr.Read())
      {
          Email o = new Email() { Fname=rdr["Fname"], MailFrom=rdr["MailFrom"],
              MailTo=rdr["MailTo"], Subject=rdr["Subject"], Body=rdr["Body"], 
              MailID=Convert.ToInt32(rdr["MailID"]) };
      
          Console.WriteLine("First Name: {0}", o.Fname);
          Console.WriteLine("MailFrom: {0}", o.MailFrom);
          Console.WriteLine("Mail To: {0}", o.MailTo);
          Console.WriteLine("Subject: {0}", o.Subject);
          Console.WriteLine("Body: {0}", o.Body);
          list.Add(o);
      } 
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have designed one sign-up form,in this form after getting all necessary values I
I have a VS 2008 WinForms project, and I recently added an existing form
I have a strange problem. I have designed a windows form application in c#
On a form designed with Qt Designer, I have two QGroupBoxes with a bunch
I have created a Windows Form Application using Visual C# 2008 Express Edition with
I have designed a form which was working fine until about an hour ago.
I have made an option page for my chrome application. Have designed the form
I have designed my GUI form in the IntelliJ IDEA GUI designer, and selected
I have designed a form where the user can enter his comment using Add
i have designed a form in extjs and exported proj to my rails appn..

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.