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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:49:11+00:00 2026-06-10T02:49:11+00:00

This error has me very confused. I have a stored procedure with two output

  • 0

This error has me very confused. I have a stored procedure with two output parameters as defined below

@agentNumber int OUTPUT,
@currentAgentNum int OUTPUT,

They are then populated using the SELECT statements below

SELECT @agentNumber = AgentNumber
FROM AgentIdentification
WHERE AgentTaxId = @ssn

SELECT @currentAgentNum = AgentNumber
FROM UniqueAgentIdToAgentId
WHERE AgentId = @agentId

In the database, AgentNumber is defined in both tables, as an int. However, when I call this stored procedure in my C# code, I get a SQL exception stating:

Error converting data type int to nvarchar.

If I change the data types of the output parameters to nvarchar, the code will execute, however it will only return nothing more than the first digit of the whole number. Below is how the variables are defined in the C# code

SqlParameter outNewAgentNumber = new SqlParameter("@agentNumber", "");//Output parameter - leave blank
SqlParameter outCurrentAgentNumber = new SqlParameter("@currentAgentNum", "");//Output parameter - leave blank

outNewAgentNumber.Direction = ParameterDirection.Output;
outCurrentAgentNumber.Direction = ParameterDirection.Output;

I add these parameters to a SqlCommand object, specify the appropriate database and commandType, then use .ExecuteNonQuery() to call the procedure. Again, what has me really confused is the error message stating that I’m using nvarchar as a data type, which could only (to the best of my knowledge) be referring to something on the database side. However, as I said I’ve double/triple checked and both AgentNumber columns are of type int.

EDIT

Changing the sqlParameter declarations to a starting value of 0 has solved this issue. I’m now running into the same problem with two other parameters.

SqlParameter outOperator = new SqlParameter("@operator", "");//Output parameter - leave blank
SqlParameter outDate = new SqlParameter("@date", "");//Output parameter - leave blank
  • 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-10T02:49:13+00:00Added an answer on June 10, 2026 at 2:49 am

    These two lines are the culprits:

    SqlParameter outNewAgentNumber = new SqlParameter("@agentNumber", "");
    SqlParameter outCurrentAgentNumber = new SqlParameter("@currentAgentNum", "");
    

    By specifying an empty string ("") as the second parameter, the ADO.NET runtime assumes it’s a string paramter. And since you didn’t specify any lengths – it probably defaults to just one character length (that’s why it’s returning only the first digit).

    So, my recommendation would be to always explicitly define the datatype (and if it’s a string – also define a length!) for your SQL parameters:

    SqlParameter outNewAgentNumber = new SqlParameter("@agentNumber", SqlDbType.Int);
    outNewAgentNumber.Direction = ParameterDirection.Output;
    outNewAgentNumber.Value = 0;
    

    or

    SqlParameter outNewAgentNumber = new SqlParameter("@agentNumber", SqlDbType.NVarChar, 50);
    outNewAgentNumber.Direction = ParameterDirection.Output;
    outNewAgentNumber.Value = "";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been confused by a very strange mex error just now . .
Subversion has very strange behavior when moving/deleting folder. I had this error Subversion unreliable:
I get this error object has no attribute 'im_func' with this class Test(object): def
Has anyone met this error? Right now i am trying to do switch from
Has anyone seen this error when working with a PHP application out of dynamic
Getting this error when try to add an item to my repositories/context: Collection has
I am receiving this error: The ViewData item that has the key 'DepartmentId' is
I'm getting this error: uncaught TypeError: Object [object Object] has no method 'on' at
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
A buddy of mine has been getting this error mesage when trying to run

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.