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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:20:31+00:00 2026-06-08T20:20:31+00:00

While sending back parameters getting this error Error : The Out Parameter must be

  • 0

While sending back parameters getting this error

Error : The Out Parameter must be assigned before control leaves the
current method

Code is

 public void GetPapers(string web, out int Id1, out int Id2)
    {
        SqlConnection conn = new SqlConnection(ConnectionString());
        conn.Open();
        SqlCommand cmd = new SqlCommand("GetPapers", conn);
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add(new SqlParameter("@URL", String(web)));

        SqlDataReader rdr = cmd.ExecuteReader();

        if (rdr.Read())
        {
            Id1 = (int)rdr["ID1"];
            Id2 = (int)rdr["ID2"];
        }

        rdr.Close();
    }

calling it as

GetPapers(web, out Id1, out Id2);

Related to this question

Related question

  • 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-08T20:20:33+00:00Added an answer on June 8, 2026 at 8:20 pm

    You are assigning Id1 and Id2 inside an if statement and compiler can’t determine if it will be assigned a value at run time, thus the error.

    You could assign them some default value before the if statement. Something like.

    Id1 = 0;
    Id2 = 0;
    
    if (rdr.Read())
    {
        Id1 = (int)rdr["ID1"];
        Id2 = (int)rdr["ID2"];
    }
    

    or specify some default values in else part of your condition.

    An out type parameter must be assigned some value, before the control leaves the functions. In your case, compiler can’t determine whether your variables will be assigned or not, because it is being assigned inside an if statement.

    See: 5.3 Definite assignment

    At a given location in the executable code of a function member, a
    variable is said to be definitely assigned if the compiler can
    prove, by static flow analysis,
    that the variable has been
    automatically initialized or has been the target of at least one
    assignment.

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

Sidebar

Related Questions

I am getting the following error while sending mail by click of a button
I asked a question a while back about how to get the current variable
I have got odd problem while sending intent with parcelable object. This object has
Salesforce can send up to 100 requests inside 1 SOAP message. While sending this
I'm having problems, while sending multiple attachments in my program. I didn't have any
I developed a sample mail program in Java. While sending mail, it throws exception
I'm learning Java and find myself sending methods around while asking for help but
I recently learned about sockets in Java and sending information back and forth from
Could all those CORBA experts out there please help me with this one. I
I'm sending this request to my WCF webservice with a Android client using ksoap2:

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.