|
-
Apr 4th, 2006, 08:35 PM
#1
Thread Starter
PowerPoster
[Resolved] [2.0] SQL data type problem
this is a wierd one but hope someone can help
I have a stored proc which returns me nvarchar (50) - the data for this column is something like this:
23vv54sdu4 (or whatever)
the stored procedure works fine as I have ran it in Query Analyzer and the syntax is correct. it gives me the return value (the example data I gave above)
in C#, I am trying to call this stored procedure however I always get this error:
"Syntax error converting the nvarchar value '23vv54sdu4 'to a column of data type int."
but no where have I set the parameters to data type int. Any ideas:
Code:
SqlParameter theCustomerIDParam = new SqlParameter("@theCustomerID", SqlDbType.Int);
theCustomerIDParam.Value = theCustomerID;
SqlParameter theReturnResult = new SqlParameter("@theReturnValue", SqlDbType.NVarChar, 50);
theReturnResult.Direction = ParameterDirection.Output;
theSQLCommand.Parameters.Add(theCustomerIDParam);
theSQLCommand.Parameters.Add(theReturnResult);
theSQLCommand.Connection.Open();
theSQLCommand.ExecuteNonQuery(); //error
theSQLCommand.Connection.Close();
Last edited by Techno; Apr 4th, 2006 at 08:55 PM.
-
Apr 4th, 2006, 08:55 PM
#2
Thread Starter
PowerPoster
Re: [2.0] SQL data type problem
Resolved.
no idea what I did. I guess I changed the stored procedure to not return the value but to leave it as is. in other words:
SQL:
Code:
//do stuff
return @theResult
now when you use ExecuteQuery() - it only returns the number of rows effected, therefore it cannot convert the returned value from SQL
you could use ExecuteScaler instead() as this returns the the first column of the first row - which is what I am looking for
Best practice:
in such a situation, use ExecuteScaler()
Last edited by Techno; Apr 4th, 2006 at 09:01 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|