error converting data type varchar to int

S

snatch_this

Hi, I'm getting an error "error converting data type varchar to int",
while trying to execute a stored procedure. Which is weird, as I don't
have any int type variables anywhere in this piece of code. Here's the
sproc:

CREATE PROCEDURE [dbo].[spAccountLogin]
@accountName varchar(50),
@accountPswd varchar(50),
@accountType varchar(20) OUTPUT
AS
SELECT @accountType = accountType FROM [dbAccounts] WHERE accountName =
@accountName AND accountPswd = @accountPswd;

And here's the c# code:

01 myConnection.Open();
02 myCommand = new SqlCommand("spAccountLogin", myConnection);
03 myCommand.CommandType = CommandType.StoredProcedure;
04 myParameter = myCommand.Parameters.AddWithValue("@accountName",
SqlDbType.VarChar);
05 myParameter.Value = strLogin;
06 myParameter = myCommand.Parameters.AddWithValue("@accountPswd",
SqlDbType.VarChar);
07 myParameter.Value = strPassword;
08 myParameter = myCommand.Parameters.AddWithValue("@accountType",
SqlDbType.VarChar);
09 myParameter.Direction = ParameterDirection.Output;
10 myCommand.ExecuteNonQuery();
11 strUserRole = myCommand.Parameters["@accountType"].Value.ToString();

The error occurs at line 10.
I'm not sure if it makes any difference, but I'm using ASP.NET 2.0.
I would appreciate any suggestions!
 
G

Guest

The only reason I can think of is that your stored proxc is outputing a
varchar and you are calling ExecuteNonQuery which returns an int. As it is
"ExecuteNonQuery" it does not expect any output other then the number of
lines changed/affected by what is supposed to be a non query call (e.g.
Insert, Update, Delete etc) although it does, according to the documentation,
fill output paramaters. Your stored proc is a query call. That could be your
problem although I've looks through the code for SqlCommand and the
associated classes and I can't see where this could be happening.

--
Brian Delahunty
Ireland

http://briandela.com/blog

INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
started in the southeast of Ireland.
 
B

Borek

Thanks a lot for your suggestion! I have figured it out now. All I had
to do was to assign ExecuteNonQuery() function to something.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top