.net output 和存储过程的真正使用
存储过程
alter proc proc_login_xingming
@zhanghao varchar(30)=null,
@xingming nvarchar(50)=null output
as
begin
if exists (select id from user_login where zhanghao=@zhanghao)
select @xingming= xingming from user_login where zhanghao=@zhanghao
else
set @xingming='none'
end
go
select * from user_login
declare @input_zhanghao varchar (30),@output nvarchar(50)
exec @input_zhanghao =proc_login_xingming '001', @output output
select @output ,@input_zhanghao
类
login_conn lc = new login_conn();
public string xingming(login_fengzhuang lf)
{
//建立连接
lc.data_lianjie();
SqlCommand cmd = new SqlCommand("proc_login_xingming", lc.conn);
cmd.CommandType = CommandType.StoredProcedure;
//定义参数
SqlParameter input_zhanghao = cmd.Parameters.Add("@zhanghao", SqlDbType.VarChar, 30);
SqlParameter output_xingming = cmd.Parameters.Add("@xingming", SqlDbType.NVarChar, 50);
//指定参数方向;
input_zhanghao.Direction = ParameterDirection.Input;
output_xingming.Direction = ParameterDirection.Output;
//给参数赋值
input_zhanghao.Value = lf.ZHANGHAO.ToString().Trim();
//打开连接执行存储过程
cmd.Connection.Open();
cmd.ExecuteNonQuery();
//获取output返回值
return output_xingming.Value.ToString();
获取
lf.ZHANGHAO = textBox1.Text.Trim().ToString();
label1.Text = lg.xingming(lf).ToString();
posted on 2010-08-01 12:03 永不言弃program 阅读(411) 评论(0) 编辑 收藏 举报