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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:00:59+00:00 2026-05-17T15:00:59+00:00

I do not clearly understand how to format the SqlDataAdapter for output variables when

  • 0

I do not clearly understand how to format the SqlDataAdapter for output variables when working with C#

Error Message:

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Code Example (Stored Procedure works fine):

private DataTable updateOrdEodHold(DataTable tb, out string mnpft,
    out string authld, out string trd, out string hld, out string extnow)
{
    // Start the connection string.
    string connstr = ConfigurationManager.ConnectionStrings
        ["LocalSqlServer"].ConnectionString;
    SqlConnection myConn = new SqlConnection(connstr);
    // Declare symbol and assign for Errors Catch Exception.
    string Symbol = "";
    string sqlComm = "dbo.UpdateOrdEodHold";
    DataTable HoldVals = new DataTable();
    SqlDataAdapter dataAdp = new SqlDataAdapter(sqlComm, myConn);
    dataAdp.SelectCommand.CommandType = CommandType.StoredProcedure;
    string ticker = (string)Convert.ToString(tb.Rows[0]["Ticker"]);
    // update Symbol for Catch ex
    Symbol = ticker.ToString();
    String company = (string)Convert.ToString(tb.Rows[0]["Company"]);
    String avgprofit = (string)Convert.ToString(tb.Rows[0]["AvgProfit"]);
    String extdte = (string)Convert.ToString(tb.Rows[0]["ExitDate"]);
    dataAdp.SelectCommand.Parameters.Clear();
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@ticker",
        SqlDbType.VarChar, 10));
    dataAdp.SelectCommand.Parameters["@ticker"].Value =
        (string)ticker.ToString();
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@company",
        SqlDbType.VarChar, 25));
    dataAdp.SelectCommand.Parameters["@company"].Value =
        (string)company.ToString();
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@avgpft",
        SqlDbType.VarChar, 10));
    dataAdp.SelectCommand.Parameters["@avgpft"].Value =
        (string)avgprofit.ToString();
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@mnpft",
        SqlDbType.VarChar, 10));
    dataAdp.SelectCommand.Parameters["@mnpft"].Direction =
        ParameterDirection.Output;
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@authld",
        SqlDbType.VarChar, 6));
    dataAdp.SelectCommand.Parameters["@authld"].Direction =
        ParameterDirection.Output;
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@hld",
        SqlDbType.VarChar, 6));
    dataAdp.SelectCommand.Parameters["@hld"].Direction =
        ParameterDirection.Output;
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@trd",
        SqlDbType.VarChar, 6));
    dataAdp.SelectCommand.Parameters["@trd"].Direction =
        ParameterDirection.Output;
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@extnow",
        SqlDbType.VarChar, 6));
    dataAdp.SelectCommand.Parameters["@extnow"].Direction =
        ParameterDirection.Output;
    dataAdp.SelectCommand.Parameters.Add(new SqlParameter("@extdte",
        SqlDbType.VarChar, 15));
    dataAdp.SelectCommand.Parameters["@extdte"].Value =
        (string)extdte.ToString();
    dataAdp.Fill(HoldVals);
    mnpft = HoldVals.Rows[0]["MinProfit"].ToString();
    authld = HoldVals.Rows[0]["AutoHold"].ToString();
    trd = HoldVals.Rows[0]["Trade"].ToString();
    hld = HoldVals.Rows[0]["Hold"].ToString();
    extnow = HoldVals.Rows[0]["ExitNow"].ToString();
    return HoldVals;
}
  • 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-17T15:01:00+00:00Added an answer on May 17, 2026 at 3:01 pm

    You need to hold a reference to the Output parameter variable so that you can access the value returned to it using parameter.Value once the adapter has executed the command.

    //Create the parameter 
    SqlParameter parameter = new SqlParameter("@mnpft", SqlDbType.VarChar);
    
    //Set the parameter direction as output
    parameter.Direction = ParameterDirection.Output;
    
    sqlCommand.Parameters.Add(parameter);
    
    SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCommand);
    sqlAdapter.Fill(dataSet);
    
    //Fetch the output parameter after doing the Fill
    string outputValue = Convert.ToString(parameter.Value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://code.google.com/appengine/docs/python/tools/uploadingdata.html is not clearly understand. Where i should call the bulkloader.py or appcfg.py? Should
I have googled this question, but I do not understand clearly what is an
This is clearly not appears like it wouldn't be a best practice. Can someone
I'm facing some questions since they're not clearly covered in the IA-32 assembly ebook
Not very technical, but... I have to implement a bad words filter in a
Not sure if this is possible or if I'm expressing correctly what I'm looking
(Not related to versioning the database schema) Applications that interfaces with databases often have
Not really getting the point of the map function. Can anyone explain with examples
Not that I'm doing something like that, but I am kind of interested how
Not sure how to ask a followup on SO, but this is in reference

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.