C# 调用带返回参数的存储过程

T_sql语句:

create proc [dbo].[getdatas]
@tid nvarchar(100),
@name nvarchar(100) output 
as 
begin
select @name=Buyer_info from boby_info where tid=@tid

end

C# ADO.NET 后台调用

 static void hh()
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "server=.;database=ManageDatas;uid=sa;pwd=sa";
            conn.Open();
            
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;

            cmd.CommandText = "getdatas";
            cmd.CommandType = CommandType.StoredProcedure;
            //设置参数
            cmd.Parameters.Add("@tid", SqlDbType.NVarChar, 100);
            cmd.Parameters.Add("@name", SqlDbType.NVarChar, 100);//此参数为输出参数 必须有size值
            //设置输出参数
            cmd.Parameters["@name"].Direction = ParameterDirection.Output;

            //给参数赋值
            cmd.Parameters["@tid"].Value = "350699082289305";

            cmd.ExecuteNonQuery();
            string name = cmd.Parameters["@name"].Value.ToString();
            conn.Close();
        }

 

posted @ 2013-07-20 17:07  JasonGu0  阅读(389)  评论(0编辑  收藏  举报