Do not use on any
shared computer
August 29, 2008 09:08pm pdt
 
[x]
Attachment Details

Use of unassigned local variable 'ReferralId' - new problem

Tags: Microsoft, Visual Studio 2008, C#
I am trying to use a variable in my application.  I originally had the variable in a try block which was giving me the same error.  I removed it from the try block and that fixed one location where it was being used.  But, I am still getting the same error when I attempt to use the variable in a different location.  Can someone tell me what I am missing this time around.

Thanks
Kenny


Here is the code:


int ReferralId;---------------------------------------------variable is initilialized here

        SqlConnection GetRefIdConn;
        GetRefIdConn = new SqlConnection();
        GetRefIdConn.ConnectionString = ConfigurationManager.ConnectionStrings["2342342ConnectionString"].ConnectionString;

        SqlCommand cmd;


        SqlDataReader RefIdReader = null;

        GetRefIdConn.Open();

        cmd = new SqlCommand("GetCurrentReferralID", GetRefIdConn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter param = new SqlParameter("@pType", SqlDbType.VarChar, 100);
        param.Value = "Referral Queue ID";
        param.Direction = ParameterDirection.Input;
        cmd.Parameters.Add(param);
        param = new SqlParameter("@pIncrement", SqlDbType.Int, 4);
        param.Value = 5;
        param.Direction = ParameterDirection.Input;
        cmd.Parameters.Add(param);
        param = new SqlParameter("@pNewId", SqlDbType.Int, 4);
        param.Direction = ParameterDirection.Output;
        cmd.Parameters.Add(param);
       
       
        //execute the command and read the current Referral ID
        RefIdReader = cmd.ExecuteReader();
        RefIdReader.Read();

        //get the value out
        if (cmd.Parameters["@pNewId"].Value != null)
        {
            ReferralId = (int)cmd.Parameters["@pNewId"].Value;
        }
       
        if (GetRefIdConn != null)
        {
            GetRefIdConn.Close();
        }
       


   
        string physicianNPI;
        physicianNPI = Session["authenticated"].ToString();



        // --- Setup Database Connectivity
        SqlConnection WriteRefIdConn;
        WriteRefIdConn = new SqlConnection();
        WriteRefIdConn.ConnectionString = ConfigurationManager.ConnectionStrings["1231234ConnectionString"].ConnectionString;

        WriteRefIdConn.Open();
        cmd = new SqlCommand("WriteReferralID", WriteRefIdConn);
        cmd.CommandType = CommandType.StoredProcedure;

       
        //------------   Submit Referral Tab  ---  Write Referral Record to Database
        cmd.Parameters.Clear();

        cmd.Parameters.Add("@REFERRAL_DATE", SqlDbType.DateTime).Value = DateTime.Now;
        cmd.Parameters.Add("@DATE_OF_APPOINTMENT", SqlDbType.DateTime).Value = DateTime.Now;

        string SelectedPatMPI = Session.Contents["SelectedPatMPI"].ToString();
        cmd.Parameters.Add("@MPI", SqlDbType.Decimal).Value = SelectedPatMPI;


        string CurrentPhysicianNPI = Session.Contents["physicianNPI"].ToString();
        cmd.Parameters.Add("@REFERRING_PROVIDER_NPI", SqlDbType.VarChar).Value = physicianNPI;


        cmd.Parameters.Add("@REFERRAL_QUEUE_ID", SqlDbType.Decimal).Value = ReferralId;------------------Here is where the error occurs
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: kwh3856
Solution Provided By: p_davis
Participating Experts: 2
Solution Grade: A
Views: 8
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by p_davis

Rank: Guru

Accepted Solution by p_davis:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by BongoMoose
Assisted Solution by BongoMoose:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628