Advertisement

05.06.2008 at 08:39AM PDT, ID: 23379844
[x]
Attachment Details

Cannot implicitly convert type object to int.  An explicit conversion exists

Asked by kwh3856 in Microsoft Visual C#.Net

Tags: Microsoft, Visual Studio 2005, C#

I am trying to setup a test value before an if statement is evaluated.  I need to know the returned value for a database read but I guess I do not understand how to pull the value correctly.  Can someone guide me in the correct way to do this?

Thanks
Kenny


GetRefIdConn.Open();

        cmd = new SqlCommand("GetCurrentReferralID", GetRefIdConn);
        cmd.CommandType = CommandType.StoredProcedure;


        // Input Parameters
         cmd.Parameters.Add("@pType", SqlDbType.VarChar, 100).Value = "Referral Queue ID";
         cmd.Parameters.Add("@pIncrement", SqlDbType.Int, 4).Value = 5;
       
       //  Output Parameters
         cmd.Parameters.Add(new SqlParameter("@pNewId", SqlDbType.Int, 4));
         cmd.Parameters["@pNewId"].Direction = ParameterDirection.Output;


       
    //    execute the command and read the current Referral ID
         cmd.ExecuteNonQuery();


        //get the value out

         int test = cmd.Parameters["@pNewId"].Value;    -------------   error occurs here

        if (cmd.Parameters["@pNewId"].Value != DBNull.Value)

        {
            ReferralId = Convert.ToInt32(cmd.Parameters["@pNewId"].Value);
            cmd.Parameters.Add("@REFERRAL_QUEUE_ID", SqlDbType.Int).Value = ReferralId;

        }
        else
            ReferralId = 0;
     
Start Free Trial
 
 
[+][-]05.06.2008 at 08:42AM PDT, ID: 21508275

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.06.2008 at 10:36AM PDT, ID: 21509301

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.06.2008 at 10:41AM PDT, ID: 21509352

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual C#.Net
Tags: Microsoft, Visual Studio 2005, C#
Sign Up Now!
Solution Provided By: p_davis
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628