First, create a stored procedure. The SQL statement is as follows:
[SQL]
USE [YCYFFJKXT]
GO
/***** Object: StoredProcedure [dbo]. [Login_UserCount] script Date: 07/17/2012 14:53:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create proc [dbo]. [Login_UserCount]
@ Zh varchar (20 ),
@ MM varchar (50 ),
@ Rowcount INT OUTPUT
AS
BEGIN
SELECT * from yhxx where zh = @ ZH and MM = @ MM
SET @ Rowcount = @ ROWCOUNT
END
C #
[Csharp]
SqlConnection conn_Local = new SqlConnection ();
Conn_Local.ConnectionString = "server =.; database = YCYFFJKXT; user id = sa; password = sa ";
Try
{
Conn_Local.Open ();
SqlCommand cmd_Count = new SqlCommand ("Login_UserCount", conn_Local );
Performance_count.commandtype = CommandType. StoredProcedure;
// Add input query parameters and assign values
__Count.parameters.add ("@ ZH", SqlDbType. VarChar );
Pai_count.parameters.add ("@ MM", SqlDbType. VarChar );
__Count.parameters ["@ ZH"]. Value = "";
__Count.parameters ["@ MM"]. Value = "B ";
// Add output parameters
Pai_count.parameters.add ("@ Rowcount", SqlDbType. Int );
__Count.parameters ["@ Rowcount"]. Direction = ParameterDirection. Output;
Performance_count.executenonquery ();
Console. WriteLine ("the number of affected rows is" + pai_count.parameters ["@ Rowcount"]. Value. ToString ());
}
Catch (Exception ex)
{
Www.2cto.com
Throw ex;
}
Finally
{
Conn_Local.Close ();
}
Console. ReadLine ();
Author: pridescc