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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:54:52+00:00 2026-06-10T21:54:52+00:00

I’m building my first web app with .net, and it needs to interact with

  • 0

I’m building my first web app with .net, and it needs to interact with a very large existing database. I have the connection set up, and have made a class that I can call to build select, insert, update and delete queries passing in several parameters.

I can connect by writing the query I want in the button click, but I want to know is this the best solution? It seems hard to debug this way, as it is mixing the database code with other code.

In the past (in other languages) I have created a class which would contain all of the database query strings and parameters which would be called by the rest of the code. That way if something simple like the stored procedure parameters change, the code is all in one place.

When I look for this in .net, I see nothing about doing it this way and I’m keen to learn the best practices.

    protected void Button1_Click(object sender, EventArgs e)
    {
       NameLabel.Text = UserNoTextBox.Text;

       string spName = "SP_SelectUser";
       SqlParameter[] parameters = new SqlParameter[]
       {
           new SqlParameter("@User_No", UserNoTextBox.Text)
       };

       DataAccess dbAccess = new DataAccess();

       DataTable retVal = dbAccess.ExecuteParamerizedSelectCommand(spName, CommandType.StoredProcedure, parameters);
 }

Update: The class I was referring to was the DataAccess class from the following website:
http://www.codeproject.com/Articles/361579/A-Beginners-Tutorial-for-Understanding-ADO-NET
(Class available at http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=361579)

Update: In the end I opted for using MVC 3 with Entity Framework – it’s great!

  • 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-10T21:54:54+00:00Added an answer on June 10, 2026 at 9:54 pm

    This is a huge topic, but a very brief view might be as follows:

    1. DataTable must die (ok, it has a few uses, but in general: it must die); consider using a custom type such as:

      public class User {
          public int Id {get;set;}
          public string Name {get;set;}
          public string EmployeeNumber {get;set;}
          // etc
      }
      

      It should also be noted that many ORM tools will generate these for you from the underlying table structure.

    2. don’t mix UI and data access; separate this code, ideally into separate classes, but at the minimum into separate methods:

      protected void Button1_Click(object sender, EventArgs e)
      {
          NameLabel.Text = UserNoTextBox.Text;
          var user = SomeType.GetUser(UserNoTextBox.Text);
          // do something with user
      }
      ...
      public User GetUser(string userNumber) {
         ... your DB code here
      }
      
    3. use a library such as an ORM (EF, LINQ-to-SQL, LLBLGenPro) or a micro-ORM (dapper, PetaPoco, etc) – for example, here’s that code with dapper:

      public User GetUser(string userNumber) {
          using(var conn = GetOpenConnection()) {
              return conn.Query<User>("SP_SelectUser",
              new {User_No = userNumber}, // <=== parameters made simple
              commandType: CommandType.StoredProcedure).FirstOrDefault()
          }
      }
      

      or with LINQ-to-SQL (EF is very similar):

      public User GetUser(string userNumber) {
          using(var db = GetDataContext()) {
              return db.Users.FirstOrDefault(u => u.User_No == userNumber);
          }
       }
      
    4. not everything needs to be a stored procedure; there used to be a huge performance difference between the two – but that is no longer the case. There are valid reasons to use them (very granular security, shared DB with multiple application consumers, a dba who thinks they are a developer), but they also create maintenance problems, especially when deploying changes. In most cases I would not hesitate to use raw (but parameterized) SQL, for example:

      public User GetUser(string userNumber) {
          using(var conn = GetOpenConnection()) {
              return conn.Query<User>(@"
      select [some columns here]
      from Users where User_No = @userNumber",
              new {userNumber}).FirstOrDefault()
          }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.