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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:43:01+00:00 2026-06-14T21:43:01+00:00

I have a wrapper that I use to query a DB2 database. The way

  • 0

I have a wrapper that I use to query a DB2 database. The way I have the wrapper set up, the connections are created and disposed within the query method. This way the consumers of my wrapper do not have to worry about managing (opening and closing) connections. Is there a way to do this with a stored procedure? Some of my users send in outbound parameters, is there a way to turn those parameters into a datatable, like I do above in my query?

    /// <summary>
    /// Query A database and return a DataTable of strings with no null
    /// </summary>
    /// <param name="txtQuery">The Query</param>
    /// <param name="list">the paramaters for the query</param>
    /// <returns>Datatable with results</returns>
    public DataTable Query(string txtQuery, params string[] list)
    {
     //create return ovject
        DataTable dt = new DataTable();
        //pull dbconnection out of pool
        using (var conn = new DB2Connection(connectionstring))
        {
            //open connection
            if (!OpenConn(conn))
            {
                throw new Exception(“failed to connect”);
            }
            try
            {
                //query db
                using (DB2Command cmd = new DB2Command())
                {
                    cmd.Connection = conn;
                    cmd.CommandText = txtQuery;
                    for (int i = 0; i < list.Length; i++)
                    {
                        DB2Parameter param = new DB2Parameter(i.ToString(), list[i]);
                        cmd.Parameters.Add(param);
                    }
                    //fill datatable
                    using (DB2DataAdapter adap = new DB2DataAdapter())
                    {
                        adap.SelectCommand = cmd;
                        adap.Fill(dt);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }                
        }
       return dt;
    }
  • 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-14T21:43:02+00:00Added an answer on June 14, 2026 at 9:43 pm

    Its not going to be as easy to do it but it is possible. I’m assuming the DB2Parameter is essentially the same as the SqlParameter in this answer…

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.aspx and related pages will be useful reading after (or during) what I’m saying here.

    Essentially when calling a procedure with output parameters you call it in the same way as you normally would. For the output parameters you pass an object in as normal but there is a Direction property on the parameter object that allows you to specify that it is an output parameter.

    Once you have called the appropriate execute method on the procedure then the values of those output parameters will be populated and can be retrieved from the parameter object.

    Putting them into a DataTable is then up to you. You can create a datatable, adding a column to it for each output parameter and then add a row in with all the values.

    The main problem with this is of course that when setting up the database call you need to know which parameters are goign to return something so you can set their direction appropriately. While you are passing just a string array then this is almost certainly not going to be possible.

    The best approach to this would be to as others have suggested in comments return all data as a dataset. Any existing procedures that currently use output parameters could have wrapper procedures created that just capture the output parameters and then put them into a select statement that you can process as above.

    The other option would be to have the caller of your Query method pass in more details about the parameters they are using (such as in or out). Personally I prefer returning all data as selects rather than using output parameters though because it makes this sort of code simpler.

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

Sidebar

Related Questions

I have a wrapper class around some objects that I want to use as
I have a main wrapper div that is set 100% width. Inside that i
I have written an O/R database wrapper that generates some wrapper methods for stored
I have to create a wrapper DLL that exports some symbols (functions). Within its
I have this line: $(#clients-edit-wrapper).height($(window).height()-150); I would like to apply that height function to
I am running a query that looks something like this: ATTACH 'db2' as db;
I have a GridView that I use to display the results of a query
I have a simple mysqli wrapper class I use for my database operations. I
I have a class 'Database' that works as a wrapper for ADO.net. For instance,
I have a wrapper div that contains arbitrary content (I don't know its length).

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.