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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:02:17+00:00 2026-06-15T22:02:17+00:00

I will try to be as Concise as I can be, please .. bear

  • 0

I will try to be as Concise as I can be, please.. bear with me, as it should be very simple …

  • the goal:

    trying to universalize a specific section of a project, that is dealing with the SQL databse transactions .

a side note

to assist you with your answer, I’ve pasted the folowing (just for Reference)

a Usage-Code : GetTestOfTablTime() returns a DataTable

class : SQLDBInteraction this is another Class – responsible for the final(SQL transaction) stage

in this code below I am constructing what I Call: “Stored Procedure’s Meta Data”

that class is the one that holds all of the SQL Db SPs :

HTSPs (HT is the company’s aliases)

this class is holding each SP (requierd) parameters

HTSPs class contains another sub Class, for all SPs Names, it only has const strings For Each SP name

public sealed class HTSPs
{

//so for example this is one of the members of this class - a stored procedure
//its mission: get evnents with specified id OF specified userId in spec' month, year..

    public sealed class GetTimesWithCustomerNames
    {
        //if I DO need Constructor for its parameters how do I properly format the constructor?
        public GetTimesWithCustomerNames()
        {
            Userid.ParameterName = ParNameUserid;
            Month.ParameterName = ParNameMonth;
            Year.ParameterName = ParNameYear;
            EventId.ParameterName = ParNameReasonid;

        }

        const string ParNameUserId = "@userId",
                     ParNameMonth = "@month",
                     ParNameYear = "@year",
                     ParNameEventId = "@eventId";

        public static SqlParameter Userid = new SqlParameter();
        public static SqlParameter Month = new SqlParameter();
        public static SqlParameter Year = new SqlParameter();
        public static SqlParameter EventId = new SqlParameter();            
    }
}

so the issue is: how do I initialize the constractor ?

what is the Proper way to have your simple customised StoredProcedure “MetaData“

Iv’e currently Completed the implementation of the Method below (apart from that issue…)

USAGE

this is a method that returns DataTable while using the HTSPs class / constuctor

using SPTime = HT_DBSchema.HTSPs.GetTimesWithCustomerNames;

private DataTable GetTestOfTablTime()
{
    SQLDBInteraction.DataContainer DC_Time = new SQLDBInteraction.DataContainer();

    SQLDBInteraction.SqlParamList parmsTime = new SQLDBInteraction.SqlParamList();
    Dictionary<SqlParameter, int> SqlCmdParDict = new Dictionary<SqlParameter, int>();
    parmsTime.SqlCmd.CommandType = CommandType.StoredProcedure;
    parmsTime.SqlCmd.CommandText = AppDb.MetaSqlSProc.Time.Name;
    parmsTime.SP_Name = AppDb.MetaSqlSProc.Time.Name;
    parmsTime.TableName = AppDb.MetaSqlTable.Time.Name;

    //While folowing implementation Does Work I comented it out to try using the SP Struct
    //ParmsTTime.SP_Params.Add(new SqlParameter(SPTime.ParNameMonth, 9));
    //ParmsTTime.SP_Params.Add(new SqlParameter(SPTime.ParNameReasonid, 1));
    //ParmsTTime.SP_Params.Add(new SqlParameter(SPTime.ParNameYear, 2012));
    //ParmsTTime.SP_Params.Add(new SqlParameter(SPTime.ParNameUserid, 3571));


    //here's where I'm currently stuck, in section below. trying to assign values for the SqlCommand
    parmsTime.SqlCmd.Parameters.AddWithValue(SPTime.ParNameMonth, 9);
    parmsTime.SqlCmd.Parameters.AddWithValue(SPTime.ParNameYear, 2012);
    parmsTime.SqlCmd.Parameters.AddWithValue(SPTime.ParNameReasonid, 1);
    SPTime.Userid.Direction = ParameterDirection.Input;
    SPTime.Userid.SqlValue = 3571;
    return DC_Time.LocalTbl_V3(ParmsTime);
 }

UPDATE

the last lines of the code above is trying to implement the parmeters assignment ,

thus it will no longer be required to use :

SQLDBInteraction.SqlParamList.SP_Params (which is List<SqlParameter>)

and instead i would really like to be able to use

SQLDBInteraction.SqlParamList.SqlCmd.Parameters

that way as it is already used for most of the requierd steps to interact with the Database,

so this is how i will drop some unnecessery usage of extra variables

while in same time i wanted to assign SqlCmd ( parmsTime.SqlCmd.Parameters.Add(......))

with the Struct – SPTime Real SqlParameters

… instead of using the strings that reperesnts their name as it is now

E.g parameter.name – (SPTime.ParNameMonth, someValue)

final stage- sql trasaction

the SQLDBInteraction Class that does the transaction

public class SQLDBInteraction
{
    public class SqlParamList
    {
        public SqlCommand SqlCmd = new SqlCommand();
        public List<SqlParameter> SP_Params = new List<SqlParameter>();
        public String SP_Name;
        public string TableName;
        public string SelectCommand;
        ///public SqlCommandType SelectedCmdType;
    }

    public class DataContainer
    {
        public DataTable LocalTbl_V3(SqlParamList Params)
        {
            SqlConnection sqlConnection;
            DataTable Usrs = new DataTable(Params.TableName);
            SqlDataAdapter sqlDataAdapter;

            using (sqlConnection = new SqlConnection(WebConfigurationManager.ConnectionStrings["HTConn"].ConnectionString))
            {
                sqlConnection.Open();

                using (Params.SqlCmd.Connection = sqlConnection)
                {
                    using (sqlDataAdapter = new SqlDataAdapter(Params.SqlCmd.CommandText, sqlConnection))
                    {
                        if (sqlDataAdapter.SelectCommand.Parameters.Count > 0 == false)
                        {
                            sqlDataAdapter.SelectCommand = Params.SqlCmd;
                            sqlDataAdapter.Fill(Usrs);
                        }
                    }
                }
            }
            return Usrs;
        }

I will really appreciate it if someone will find what am I doing wrong with the part of the stored procedure’s Parameters Assigned to the SQL Command

  • 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-15T22:02:18+00:00Added an answer on June 15, 2026 at 10:02 pm

    so at last … this is my own answer to the ‘problem’.

    as there will always be opportunities to fine-tune …and polish it even more,

    though I did find, a way to implement the solution .

    for starters :

    Summary

    connecting between a 3 stages proccess – the data extraction, as follows:

    1’st stage : assigning the name and id’s for the table and its stored procedure
    within the struct

    2’nd stage : constructing the sql parameter collection / List <SqlParameter>
    for the final sql command .

    the 3’rd stage : by using these structs to format / construct the sql command,

    will in return, get a System.Data DataTable as requested, via the sql instructions
    in the stored procedure… naturally.

    prepering a background – for code ReUse

    these first 2 blocks of code are sotred in two separated files

    the first file is for holding the sql databse schema

    table names , tables (custom) IDs , Columns names , and stored procedures names and parameters.

    public sealed class HTDB_Tables
    {
        // this is the class that will hold all Sql server - tables Names
    
        public const string TblTime = "tblTime";
    }
    
     // the class for Stored Procedures Paramaters - (for each stored procedure)
    public sealed class HTDB_SPs
    {
        // for example this is one of the stored procedures
        public sealed class GetTimesWithCustomerNames
        {
    
            public static List<SqlParameter> SqlParlst(string SlctdUserID, string SlctdMonth, string SlctdYear, string SlctdEventID)
            {
                SqlParameter Userid = new SqlParameter( UserIdParName, SlctdUserID);
                SqlParameter Month = new SqlParameter(MonthParName, SlctdMonth);
                SqlParameter Year = new SqlParameter(YearParName, SlctdYear);
                SqlParameter EventId = new SqlParameter(EventIdarName, SlctdEventId);
    
                List<SqlParameter> RetSqlParLst  = new List<SqlParameter>();
                retSqlParLst.Add(UserId);
                retSqlParLst.Add(Month);
                retSqlParLst.Add(Year);
                retSqlParLst.Add(EventId);
    
                return retSqlParLst;
            }
    
    
    
            const string UserIdParName = "@userId",
                         MonthParName = "@month",
                         YearParName = "@year",
                         EventIParName = "@eventId";
      
        }
    }
    
    // a numeric value that's used to reference the table
    // the id is passed as a parameter to a javascript-Jquery Update function 
    // through the textbox control - "textchange event" - attribute,
    // as reference to which table to send the updated data .
    
    // then it is proccessed  in code behind  as table id  inside the application 
    // via a switch on the parameter sent by Jquery-ajax function
    
    
    public sealed class HTDB_tblIDs
    {
        public const int tblTime = 1;
    
       //this is only an example , for one of tables 
       //as it requierd that all sql database tables(that i want to work with this project)
       // will be added here too
       // this could be done via using code smith or through few simple 
      // steps you could do it via C# method that will list all your 
      // database tables names etc'
    }
    

    the Second file is a general usage Helper nameapace, that stores all Helper classes,

    and one of the classes (next block of code) , is the one that hodls the structs

    one for the table and another for the stored procedure,

    these two, will be assinged, later in the application’s code behind.

                public class DBMetaDetails
                {
                    public struct DbTable
                    {
                        public DbTable(string tableName, int tableId): this()
                        {
                            this.Name = tableName;
                            this.ID = tableId;
                        }
                        public string HtmlOutput;
                        public string Name { get; private set; }
                        public int ID { get; private  set; }
                    }
    
                    public struct SProc
                    {
                        public SProc(string SProcName, int SprocID, List<SqlParameter> CurrSpParList)
                            : this()
                        {
                            this.Name = SProcName;
                            this.ID = SprocID;
                            this.SpParList = CurrSpParList;
                        }
                        public string Name { get; private set; }
                        public int ID { get; private set; }
                        public List<SqlParameter> SpParList { get; private set; }
                    }
                }
    

    so both of the codes above are in two separated files …

    meaning codes above could be used in every application i need to create,

    so it’ll be very easy to implement after this initial background work done.

    • second part

    implementation in current project.

    the next codes are used in the "current project" code behind aspx.cs

    the implementation of struct for the System.Data DataTable

    and its stored procedure, that will be used / assigned to the SqlCommand

    public sealed class AppDb
    {
        public sealed class SqlTableMeta
        {    
          //id -for usage by jquery, name for the DataTable returnd in the next block of code
            public static DbTbl Time = new DbTbl(HTDB_Tables.TblTime, HTtIDs.tblTime);
    
        }
        public sealed class SqlSProcMeta
        {
    
            public static SProc Time = new SProc(HTSPs.SP_GetTimesWithCustomerNames,
                                                 HTtIDs.SProcTime,
                                                 HTSPs.GetTimesWithCustomerNames.SqlParLst("3571", "9", "2012", "1"));
        }
    
    }
    

    the final two steps that could have been in one , though what i want to see is

    that the project would have the smallest footprint of extra codes needed to get the data

    so i guess the second part that is doing the actual interaction with database

    should be soon after tests are complete moved to the Helpers section and out of the code behind section of every application .

    so next are codes that will gather all preperations and data setup into action

    private DataTable GetDbTable(DbTbl dbTbl, SProc Sprc)
    {
        SQLDBInteraction.DataContainer DC_Time = new SQLDBInteraction.DataContainer();
    
        //ParmsTime- a class instace, for passing a set of required parameters to final stage
        SQLDBInteraction.SqlParamList ParmsTime = new SQLDBInteraction.SqlParamList();
        
        ParmsTime.SqlCmd.CommandType = CommandType.StoredProcedure;
    
        //using the stored procedure struct:  assigend to Sqlcommand as its CommandText 
        ParmsTime.SqlCmd.CommandText = Sprc.Name;
    
        //using stored procedure parameters list - allso via a struct above codes
        ParmsTime.SqlCmd.Parameters.AddRange(Sprc.SpParList.ToArray());
    
        //using DataTable struct to assign the data table a name
        ParmsTime.TableName = dbTbl.Name;
    
        return DC_Time.LocalTbl_V3(ParmsTime);
    }
    

    the final stage: sql database interaction

    public class SQLDBInteraction
    {
    
        public class SqlParamList
        {
    
            public SqlCommand SqlCmd = new SqlCommand();
            public List<SqlParameter> SP_Params = new List<SqlParameter>();
            
            public string TableName;
            public string SelectCommand;
            ///public SqlCommandType SelectedCmdType;
        }
    
        public class DataContainer
        {
    
    
            public DataTable LocalTbl_V3(SqlParamList Params)
            {
                SqlConnection sqlConnection;
                DataTable retDt = new DataTable(Params.TableName);
                SqlDataAdapter sqlDataAdapter;
    
                using (sqlConnection = new SqlConnection(WebConfigurationManager.ConnectionStrings["useyourwebconfigconnection"].ConnectionString))
                {
                    sqlConnection.Open();
    
                    using (Params.SqlCmd.Connection = sqlConnection)
                    {
    
                        using (sqlDataAdapter = new SqlDataAdapter(Params.SqlCmd.CommandText, sqlConnection))
                        {
                            if (sqlDataAdapter.SelectCommand.Parameters.Count > 0 == false)
                            {
                                sqlDataAdapter.SelectCommand = Params.SqlCmd;
                                sqlDataAdapter.Fill(retDt);
                            }
                        }
    
                    }
    
                }
                return retDt;
            }
    
    
    
       }
    
    
    }
    

    this is only a test, yet it works very fast
    and very easy to implemet , it will fit perfectly as it is for personal or small buisness use

    comments are very welcome …

    thanks

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

Sidebar

Related Questions

I will try to be specific if I can - please be patient, first
I will try to walk you through this very slow. I am trying to
I will try and word this question the best I can, for it is
I will try to make this as clear as I can, but if you
I will try to be as clear as possible because I can't get anybody
I will try to keep this as simple as possible. I have a rather
I will try to explain a simple app scenario: My app goes right to
I will try and set the scene as best i can. *lights candle What
I will try to explain my problem as much as I can. I have
I will try to keep it simple: In my main activity I make a

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.