Advertisement

05.06.2008 at 08:10AM PDT, ID: 23379716
[x]
Attachment Details

The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects

Asked by kwh3856 in Microsoft Visual C#.Net, SQL Server 2005

Tags: Microsoft, Visual Studio 2005, C#

I am trying to add a parameter to my cmd object but keep getting this error message.  Can someone clue me in where I am going wrong.

Thanks
Kenny



 int ReferralId = 0;

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

        SqlCommand cmd;


       

        GetRefIdConn.Open();

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


        // Input Parameters
         cmd.Parameters.Add(new SqlParameter("@pType", SqlDbType.VarChar, 100).Value = "Referral Queue ID"); ---- Error occurs here
         cmd.Parameters.Add(new SqlParameter("@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

        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;
     
       
        if (GetRefIdConn != null)
        {
            GetRefIdConn.Close();
        }Start Free Trial
[+][-]05.06.2008 at 08:16AM PDT, ID: 21508026

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

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