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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:44:37+00:00 2026-06-07T06:44:37+00:00

I have an asp.net project done in C# (my C# syntax is very rusty)

  • 0

I have an asp.net project done in C# (my C# syntax is very rusty) and am using the built in database it creates with the project. I’ve created a table called aspnet_Tutorials that (for now) stores two columns of user submitted data: TutorialName and TutorialContent. Very simple, it’s a learning project.

What I need to do is create a list from the first column of aspnet_Tutorials to use it to create a “directory” of the tutorials on a page. The part I’m having trouble with, mostly syntactically, is connecting to and iterating over the column to get the values into a list. Could anyone provide a straight forward example of this? And possibly explain what’s going on in the code.

public class TutorialsDirDAL
    {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();


        public List<string> DisplayTutorials() //parameters? String qry?
        {
           //query the database table, foreach loop over the data, place it into a list?
        }
    }

I know how to write simple sql queries. But I’ve seen a couple different set ups for this in my Googling spree. I currently have the following for a query, feel free to pick it apart or offer a better solution than using a query.

cmd.CommandText = "SELECT * FROM ASPNET_TUTORIALS (TutorialTitle)"
                + "VALUES (@tutorialTitle)";

Thank you!

  • 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-07T06:44:39+00:00Added an answer on June 7, 2026 at 6:44 am

    ebad86’s answer is acceptable but since you are obviously learning I think introducing OO principals muddy the water with what you are trying to learn at this point.

    Here is a basic method:

    private void GetData()
    {
       //The object that will physically connect to the database
       using(SqlConnection cnx = new SqlConnection("<your connection string>")
       {
                //The SQL you want to execute
               SqlCommand cmd = new SqlCommand("SELECT * FROM ASPNET_TUTORIALS");
               //Open the connection to the database
               cnx.Open();
               //execute your command
               using (IDataReader dataReader = cnx.ExecuteReader(cmd))
               {
                 //Loop through your results
                 while(dataReader.Read())
                 {
                    //do whatever to the data
                    ListItem item = new ListItem(Convert.ToString(dataReader["TutorialName"])); 
                    lst.Items.Add(item);
                 }
               }
       }
    }
    

    This is all very straightforward. The part you are most interested in is the while loop though. The loop will go through all of the returned records and you can do whatever you need to do with them. In my example I have assumed that there is a ListBox named ‘lst’ and I am simply adding ListItems to it that will have the name of whatever ‘TutorialName’ is. You can make literally do whatever you need to do with the data at this point. To fit your example (returning a List) you would do this:

    private List<string> GetData()
    {
       List<string> lst = new List<string>();
       //The object that will physically connect to the database
       using(SqlConnection cnx = new SqlConnection("<your connection string>")
       {
                //The SQL you want to execute
               SqlCommand cmd = new SqlCommand("SELECT * FROM ASPNET_TUTORIALS");
               //Open the connection to the database
               cnx.Open();
               //execute your command
               using (IDataReader dataReader = cnx.ExecuteReader(cmd))
               {
                 //Loop through your results
                 while(dataReader.Read())
                 {
                    lst.Add(Convert.ToString(dataReader["TutorialName"]));
                 }
               }
       }
       return lst;
    }
    

    Please respond if you have any questions.

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

Sidebar

Related Questions

I have a project that needs to be done using ASP.NET. Currently, I'm using
I have done a web project ( using C# + SQL CE + ASP.NET
I have an ASP.NET project connecting to a database. A web page sends a
I have an ASP.NET project which is a front-end to a database. In addition
I have an ASP.Net project using AJAX that I am putting on a server
We have a ASP.NET website project. In the past, we had been using asmx
I have a pretty big web application that I created last year using ASP.NET
I have done hands full of project with AspNetSqlMembershipProvider. Now, I have asp.net website
I've created this ASP.Net application and need to record what the users have done
I have a very large ASP.NET project that i need to make good with

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.