Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CmdUsers.ExecuteNonQuery() error
Message
From
26/01/2006 19:35:43
 
 
To
26/01/2006 17:23:53
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01090740
Message ID:
01090775
Views:
7
Sergio,

What error are you getting? At first glance, everything looks ok. Have you tried using SQL Profiler to see what is actually getting passed to SQL Server? (if anything, it may be failing *before* it gets to SQL Server).

The only thing I see that looks different from the way I do it, is that I declare the Direction to be ParameterDirection.InputOutput instead of just Output.

~~Bonnie




>I am trying to execute an store procedure from c#.
>
>I would like to return a value from my store procedure but I get an error.
>I get the error on the 'cmdUsers.ExecuteNonQuery()' line.
>
>
>Here is the code :
>
>SqlConnection cnUsers = new SqlConnection("server=\\myserver;integrated security=true;database=shg");
>// Create command object
>SqlCommand cmdUsers = new SqlCommand("USP_validateuser",cnUsers);
>cmdUsers.CommandType = CommandType.StoredProcedure;
>cmdUsers.Parameters.Add("@cUser_id",SqlDbType.Char,40);
>cmdUsers.Parameters["@cUser_id"].Value = "sortiz";
>cmdUsers.Parameters.Add("@cPassword",SqlDbType.Char,40);
>cmdUsers.Parameters["@cPassword"].Value = "gabriel";
>cmdUsers.Parameters.Add("@nCount",SqlDbType.Int);
>cmdUsers.Parameters["@nCount"].Direction = ParameterDirection.Output;
>cnUsers.Open();
>int iCount ;
>cmdUsers.ExecuteNonQuery();
>iCount = (int)cmdUsers.Parameters["@nCount"].Value;
>cnUsers.Close();
>return iCount;
>
>
>
>Here is the store procedure code :
>
>
>
>CREATE PROCEDURE USP_VALIDATEUSER @cUser_Id char(40),@cPassword char(40),@nCount int OUTPUT AS
>SET @nCount =(SELECT COUNT(*) FROM Users WHERE cUser_Id =@cUser_Id AND cPassword = @cPassword)
>RETURN
>
>GO
>
>
>
>
>
>
>Any help is appreciated.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform