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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:19:55+00:00 2026-05-16T05:19:55+00:00

I know this maybe simple and I know the code I am posting is

  • 0

I know this maybe simple and I know the code I am posting is wrong but I am getting close I think.

I am wanting to get the function below from the file pageDAL.cs to return the object page with the values for whatever pageID I pass in. If I do not need to use a DataSet or DataTable that is fine. What is the best way?

 public page getPage(int _pageID)
    {
      DataTable dt = new DataTable;
      using (SqlDataAdapter da = new SqlDataAdapter("select PageID,ParentID,CategoryID,Name,PageHTMLContent,NavigationText,TopMenu,SubMenu,DisplayOrder,Active from Page where PageID = " + _PageID, ConnectionStrings.StaceysCakes))
      {
        da.Fill(dt);
        dt.AsEnumerable().Select(r => page)
      {
        page myPageOBJ = new page();
        myPageObj.PageID = r.Field<int>("PageID"),
        ParentID = r.Field<int>("ParentID"),
        CategoryID = r.Field<int>("CategoryID"),
        Name = r.Field<string>("Name"),
        PageHTMLContent = r.Field<string>("PageHTMLContent"),
        NavigationText = r.Field<string>("NavigationText"),
        TopMenu = r.Field<bool>("TopMenu"),
        SubMenu = r.Field<bool>("SubMenu"),
        DisplayOrder = r.Field<int>("DisplayOrder"),
        Active = r.Field<bool>("Active"),
      });
      }
     return page;
    }

page.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace sc2.Models.page
{  
  public class page
  {
    public int PageID { get; internal set; }
    public int ParentID { get; internal set; }
    public int CategoryID { get; internal set; }
    public string Name { get; internal set; }
    public string PageHTMLContent { get; internal set; }
    public string NavigationText { get; internal set; }
    public bool TopMenu { get; internal set; }
    public bool SubMenu { get; internal set; }
    public int DisplayOrder { get; internal set; }
    public bool Active { get; internal set; }

    public page()
    {
    }

  }
}

pageBLL.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
//using sc2.Models;

namespace sc2.Models.page
{
  public class pageBLL
  {

    pageDAL myPageDAL = new pageDAL();


    public pageBLL(){
    }

    public page getPage()
    {
      page PageOBJ = new page();
      return PageOBJ;
    }

    public page getPage(int _pageID)
    {
      return myPageDAL.getPage(_pageID);
    }

    public string save(page _page)
    {
      return myPageDAL.save(_page);
    }


    public List<page> Select()
    {
      return (myPageDAL.Select());
    }

    public List<page> Select(string _OrderBy)
    {
      return (myPageDAL.Select(_OrderBy));
    }

    public DataSet Get(int _PageID)
    {
      return (myPageDAL.Get(_PageID));
    }

    public void DeletePage(int _PageID)
    {
      myPageDAL.DeletePage(_PageID);
    }


  }
}

pageDLL.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Diagnostics;

namespace sc2.Models.page
{
  public class pageDAL
  {

    public pageDAL()
    {
    }

    // List Order By
    public List<page> Select(string _OrderBy)
    {
      string sqlStatement = _OrderBy;
      return All(sqlStatement);
    }


    // Select List of Objects
    public List<page> Select()
    {
      string sqlStatement = "DisplayOrder";
      return All(sqlStatement);
    }

    // Return List of Objects
    public List<page> All(string _sqlStatement)
    {
      var sqlResults = new DataTable();
      string sqlStatement = "select PageID,ParentID,CategoryID,Name,PageHTMLContent,NavigationText,TopMenu,SubMenu,DisplayOrder,Active from page";
      if (!String.IsNullOrEmpty(_sqlStatement))
      {
        sqlStatement += " Order By " + _sqlStatement;
      }
      using (SqlConnection conn = new SqlConnection(ConnectionStrings.StaceysCakes))
      {
        using (SqlCommand command = new SqlCommand(sqlStatement, conn))
        {
          var adapter = new SqlDataAdapter(command);
          adapter.Fill(sqlResults);
        }
      }

      return sqlResults.AsEnumerable().Select(r => new page()
      {
        PageID = r.Field<int>("PageID"),
        ParentID = r.Field<int>("ParentID"),
        CategoryID = r.Field<int>("CategoryID"),
        Name = r.Field<string>("Name"),
        PageHTMLContent = r.Field<string>("PageHTMLContent"),
        NavigationText = r.Field<string>("NavigationText"),
        TopMenu = r.Field<bool>("TopMenu"),
        SubMenu = r.Field<bool>("SubMenu"),
        DisplayOrder = r.Field<int>("DisplayOrder"),
        Active = r.Field<bool>("Active"),
      }).ToList();


    }

    public page getPage(int _pageID)
    {
      DataTable dt = new DataTable;
      using (SqlDataAdapter da = new SqlDataAdapter("select PageID,ParentID,CategoryID,Name,PageHTMLContent,NavigationText,TopMenu,SubMenu,DisplayOrder,Active from Page where PageID = " + _PageID, ConnectionStrings.StaceysCakes))
      {
        da.Fill(dt);
        dt.AsEnumerable().Select(r => page)
      {
        page myPageOBJ = new page();
        myPageObj.PageID = r.Field<int>("PageID"),
        ParentID = r.Field<int>("ParentID"),
        CategoryID = r.Field<int>("CategoryID"),
        Name = r.Field<string>("Name"),
        PageHTMLContent = r.Field<string>("PageHTMLContent"),
        NavigationText = r.Field<string>("NavigationText"),
        TopMenu = r.Field<bool>("TopMenu"),
        SubMenu = r.Field<bool>("SubMenu"),
        DisplayOrder = r.Field<int>("DisplayOrder"),
        Active = r.Field<bool>("Active"),
      });
      }
     return page;
    }

    // (DataSet) get
    public DataSet Get(int _PageID)
    {
      using (SqlDataAdapter da = new SqlDataAdapter("select PageID,ParentID,CategoryID,Name,PageHTMLContent,NavigationText,TopMenu,SubMenu,DisplayOrder,Active from Page where PageID = " + _PageID, ConnectionStrings.StaceysCakes))
      {
        DataSet ds = new DataSet();
        da.Fill(ds, "Pages");
        return (ds);
      }
    }

    // Save
    public string save(page _page)
    {
      string errorMessage = "";

      if (_page.CategoryID == 0)
      {
        InsertPage(_page.Name, _page.PageHTMLContent, _page.NavigationText, _page.TopMenu, _page.SubMenu, _page.DisplayOrder, _page.Active);
      }
      else
      {
        UpdatePage(_page.CategoryID, _page.Name, _page.PageHTMLContent, _page.NavigationText, _page.TopMenu, _page.SubMenu, _page.DisplayOrder, _page.Active);
      }
      return errorMessage;
    }


    // Insert Page
    public string InsertPage(string _Name, string _PageHTMLContent, string _NavigationText, bool _TopMenu, bool _SubMenu, int _DisplayOrder, bool _Active)
    {
      SqlConnection myConnection = new SqlConnection(ConnectionStrings.StaceysCakes);
      string SqlStatement = "insert into Page (Name,PageHTMLContent,NavigationText,TopMenu,SubMenu,DisplayOrder,Active) values ('"
        + _Name + "','"
        + _PageHTMLContent + "','"
        + _NavigationText + "','"
        + _TopMenu + "','"
        + _SubMenu + "',"
        + _DisplayOrder + ",'"
        + _Active + "');";
      string errorMessage = "";
      try
      {
        SqlCommand myCommand = new SqlCommand(SqlStatement);
        myCommand.Connection = myConnection;
        myConnection.Open();
        myCommand.ExecuteNonQuery();
      }
      catch (Exception e)
      {
        errorMessage = "There was an error with the database insert.";
        Trace.Write("Database unavailable with Message: ", e.Message);
        Trace.Write("Stack Trace: ", e.StackTrace);
        // Throw the exception higer for logging and notification
        throw;

      }

      // Clean up any loose ends.
      finally
      {
        myConnection.Close();
      }

      // Return the error message if there is one.
      return errorMessage;

    }

    // Update Page
    public string UpdatePage
      (int _PageID,
       string _Name,
       string _PageHTMLContent,
       string _NavigationText,
       bool _TopMenu,
       bool _SubMenu,
       int _DisplayOrder,
       bool _Active)
    {
      string SqlStatement = "UPDATE Page SET Name='" + _Name + "', PageHTMLContent='" + _PageHTMLContent + "', NavigationText='" + _NavigationText + "', TopMenu='" + _TopMenu + "', SubMenu='" + _SubMenu + "', DisplayOrder=" + _DisplayOrder + ", Active='" + _Active + "' where PageID = '" + _PageID + "'";
      SqlConnection myConnection = new SqlConnection(ConnectionStrings.StaceysCakes);
      string errorMessage = "";
      try
      {
        SqlCommand myCommand = new SqlCommand(SqlStatement);
        myCommand.Connection = myConnection;
        myConnection.Open();
        myCommand.ExecuteNonQuery();
      }
      catch (Exception e)
      {
        errorMessage = "There was an error with the database update.";
        Trace.Write("Database unavailable with Message: ", e.Message);
        Trace.Write("Stack Trace: ", e.StackTrace);
        // Throw the exception higer for logging and notification
        throw;
      }

      // Clean up any loose ends.
      finally
      {
        myConnection.Close();
      }

      // Return the error message if there is one.
      return errorMessage;
    }

    // Delete Page
    public string DeletePage(int _PageID)
    {

      string SqlStatement = "Delete from Page where PageID = '" + _PageID + "'";

      SqlConnection myConnection = new SqlConnection(ConnectionStrings.StaceysCakes);
      string errorMessage = "";
      try
      {
        SqlCommand myCommand = new SqlCommand(SqlStatement);
        myCommand.Connection = myConnection;
        myConnection.Open();
        myCommand.ExecuteNonQuery();
      }
      catch (Exception e)
      {
        errorMessage = "There was an error with the database delete.";
        Trace.Write("Database unavailable with Message: ", e.Message);
        Trace.Write("Stack Trace: ", e.StackTrace);
        // Throw the exception higer for logging and notification
        throw;
      }

      // Clean up any loose ends.
      finally
      {
        myConnection.Close();
      }

      // Return the error message if there is one.
      return errorMessage;
    }
  }
}
  • 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-05-16T05:19:56+00:00Added an answer on May 16, 2026 at 5:19 am

    Have a look at the SqlDataReader class. It is a lot simpler and has less overhead than the SqlDataAdapter and DataTable.

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx

    Also, look here

    var results = new List<page>();
    string queryString = "SELECT PageID,ParentID...";
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlCommand command = new SqlCommand(queryString, connection);
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            page p= new page();
            p.PageID = reader["PageID"]; 
            //...
            results.Add(p);
        }
        reader.Close();
    }
    return results;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use: SELECT p.id as a, p.url as b, t.id as… May 17, 2026 at 3:22 am
  • Editorial Team
    Editorial Team added an answer There are two parts to the problem First Issue You… May 17, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer I thought I'd show the regex approach, too. It doesn't… May 17, 2026 at 3:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I know this maybe a very basic question but I'm having a bit of
I know this maybe a basic question but I just can't seem to find
I know this may be a noob question, but it's bugging the heck out
This may be a no-brainer for the WPF cognoscenti, but I'd like to know
This question may be too product specifc but I'd like to know if anyone
I know this might be a no-brainer, but please read on. I also know
I know this isn't strictly a programming question but y'all must have experienced this.
I know this is a broad question, but I've inherited several poor performers and
I know this is not programming directly, but it's regarding a development workstation I'm
Maybe I just don't know .NET well enough yet, but I have yet to

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.