Use stored procedures in c #

Source: Internet
Author: User
Tags rowcount

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.