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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:35:33+00:00 2026-06-04T14:35:33+00:00

I’m writing an application which first connect to the database and retrieves a dt

  • 0

I’m writing an application which first connect to the database and retrieves a dt containing a list of all the stored procedures, inputs and their associated datatypes. The user then selected a SProc from the combobox and has to enter in the necessary inputs. The app will then connect to the database and run the selected SProc with the user specified inputs and return the results in a datatable.

What I’m unsure about is if I need to write a specific method for each SProc. I’m assuming so since I don’t see how I could state what the parameters are otherwise.

Apologies for not making this clear the first time. Let me know if this still isn’t clear enough.

Example is shown below (this is someone else’s code)

public static GetDaysDTO GetDays(int offset)
    {
        GetDaysDTO ret = new GetDaysDTO { TODAY = DateTime.Now, TOMORROW = new DateTime(2012, 01, 01) };
        SqlConnection con = new System.Data.SqlClient.SqlConnection(@"Server = FrazMan-pc\Programming; Database = master; Trusted_Connection = True");
        SqlCommand cmd = new System.Data.SqlClient.SqlCommand
        {
            CommandText = "GetDays",
            CommandType = System.Data.CommandType.StoredProcedure,
            CommandTimeout = 1,
            Connection = con,
            Parameters = { new System.Data.SqlClient.SqlParameter("@offset", System.Data.SqlDbType.Int) { Value = offset } }
        };
        using (con)
        {
            con.Open();
            using (System.Data.SqlClient.SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    ret.TODAY = DateTime.Parse(reader[0].ToString());
                    ret.TOMORROW = DateTime.Parse(reader["TOMORROW"].ToString());
                }
            }
        }

        return ret;
    }
  • 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-04T14:35:35+00:00Added an answer on June 4, 2026 at 2:35 pm

    What you’re looking for is a design pattern called Factory and a way to tell which typed data table to create on each SP call

    If you have the list of the parameters for each procedure, u could instantiate the Parameters object via a loop:

    This class will be used to fill the params of the sp received from the db

    class ParamData
    {
      public object Data;
      public SqlDbType type;
      public string ParamName;
    }
    

    and then later on, when calling the sp, u should also pass thie ParamData object to the method, and used it to fill the params of ur sp dynamicly in a loop:

    List<ParamData> list = new List<ParamData>();
    //initialize command here as u did
    SqlCommand cmd;
    foreach (ParamData param in list)
    {
      SqlParameter sqlParam = new SqlParameter(param.ParamName, param.type);
      sqlParam.Value = param.Data;
      cmd.Parameters.Add(sqlParam);
    }
    //execute the command
    //fill the datatable with result
    DataTable dt = GetTableBySPName("GetDays");
    SqlDataReader reader = cmd.ExecuteReader();
    dt.Load(reader);
    

    The only thing you need to add is the mapping between ur typed datatables and the returned table by the procedure.

    You can add a method to do this:

    private DataTable GetTableBySPName(string name)
    {
      DataTable dt = null;
      switch (name)
      {
       case "GetDays":
       {
        dt = new GetDatsDTO();
        break;
       }
      }
     return dt;
    }
    

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I have a reasonable size flat file database of text documents mostly saved in

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.