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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:59:29+00:00 2026-06-08T07:59:29+00:00

I am writing a method that will query a table and return a Dataset

  • 0

I am writing a method that will query a table and return a Dataset object containing the specified column. Moreover, I have a problem with my Username & Password, so I am using Windows authentication for the same but I am not too sure about that in my snippet I have written till now.

 protected void GetProgramList()
    {
        SqlConnection cn = new SqlConnection("server=Daffodils-PC/sqlexpress;Database=Assignment1;Trusted_Connection=Yes;");
        SqlCommand cmd = new SqlCommand("SELECT ProgramName FROM Program", cn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet1 ds1 = new DataSet1();

    }

I have been trying to follow official MS documentation but I am not sure where I am going? Can someone help me with some links or snippets?

  • 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-08T07:59:32+00:00Added an answer on June 8, 2026 at 7:59 am

    I would say you have 2 options here:
    1. to make a DataSet class variable, so its reference can be accessed from all over the class (set its access modifier to public so it can be accessed from other classes)
    2. or create a method with its return type of DataSet. But in this case on the other side must be set to receive the DataSet as well:

    //2. solution:

        private void GetData()
        {
            //from inside some method:
            DataSet ds = GetProgramList();
        }
    
        protected DataSet GetProgramList()
        {
            DataSet ds1 = new DataSet();
            using (SqlConnection cn = new SqlConnection("server=Daffodils-PC/sqlexpress;Database=Assignment1;Trusted_Connection=Yes;"))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(@"SELECT ProgramName FROM Program", cn))
                    da.Fill(ds1, "TableName1");
            }
            return ds1;
        }
        //
    
    
    //1. solution:
    class YourClass
    {
        DataSet ds1;
        protected void GetProgramList()
        {
            SqlConnection cn = new SqlConnection("server=Daffodils-PC/sqlexpress;Database=Assignment1;Trusted_Connection=Yes;");
            SqlCommand cmd = new SqlCommand("SELECT ProgramName FROM Program", cn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            ds1 = new DataSet();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a program that will query an MS access database, return the
I'm writing an action method that will store a new object in a database.
I'm writing a method that will resize the columns in a datagridview so that
I am writing a deserialization method that converts xml to a Java object. I
I'm writing tetris right now, I have a method that drops figures one by
I have a method I'm writing that uses reflection to list a class's static
I am writing a bit of JavaScript that uses the Object.bind method. funcabc =
I have a method, which will accept a parameter of a JQuery Object and
I'm trying to writing a generic method that will load a record of a
I will be writing an IOS app that will query data from a server.

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.