.net 调用SQL数据库存储过程 并取得返回值

来源:互联网 发布:20以内手指快算法视频 编辑:程序博客网 时间:2024/06/04 18:12
 SqlParameter returnValue= new SqlParameter("@ReturnValue",SqlDbType.Decimal,4,ParameterDirection.Output,true,8,2,null, DataRowVersion.Default,null);//在此处设置返回值的类型,长度,精确度  ,是否为空等(构造函数最长的重载) using (SqlConnection connection = new SqlConnection(connectionString))            {            SqlCommand command = new SqlCommand(storedProcName, connection);//存储过程名,连接名            command.CommandType = CommandType.StoredProcedure;//设置类型为存储过程 ,默认为text             connection.Open();              rowsAffected = command.ExecuteNonQuery();//执行存储过程 返回受影响的行数              obj returnValue=command.Parameters["@ReturnValue"].Value//获得返回值(obj类型,需要转换)             }
0 0