易网时代-编程资源站
Welcome
微信登录
编程资源
图片资源库
蚂蚁家优选
PDF转换器
软件资源
软件开发
、
小程序制作
、
系统集成与运维
、
空间租用
、
硬件开发
、
视频监控
、
技术咨询与支持
——联系电话:0311-88999002/88999003
首页
/
操作系统
/
Linux
/
C#中使用存储过程
首先创建存储过程,sql语句如下所示:
USE [YCYFFJKXT]
GO
/****** 对象: StoredProcedure [dbo].[Login_UserCount] 脚本日期: 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#中调用
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);
cmd_Count.CommandType = CommandType.StoredProcedure;
//添加输入查询参数、赋予值
cmd_Count.Parameters.Add(
"@ZH"
, SqlDbType.VarChar);
cmd_Count.Parameters.Add(
"@MM"
,SqlDbType.VarChar);
cmd_Count.Parameters[
"@ZH"
].Value =
"A"
;
cmd_Count.Parameters[
"@MM"
].Value =
"B"
;
//添加输出参数
cmd_Count.Parameters.Add(
"@Rowcount"
, SqlDbType.Int);
cmd_Count.Parameters[
"@Rowcount"
].Direction = ParameterDirection.Output;
cmd_Count.ExecuteNonQuery();
Console.WriteLine(
"受影响的行数是"
+cmd_Count.Parameters[
"@Rowcount"
].Value.ToString());
}
catch
(Exception ex)
{
throw
ex;
}
finally
{
conn_Local.Close();
}
Console.ReadLine();
收藏该网址
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图