这个存储过程用winform怎么调用???????????
create procedure usp_OutStudent
@name char(10),
@sex char(10) output
as
select @sex=性别 from mytable where 姓名=@name

解决方案 »

  1.   

     private DataTable LoadData(int PageIndex)  
            {  
                 SqlConnection con = new SqlConnection(this.ConnectStr());  
                SqlCommand cmd = new SqlCommand("pagination", con);  
                cmd.CommandType = CommandType.StoredProcedure;  
                con.Open();  
                cmd.Parameters.Add(new SqlParameter("@PageSize", SqlDbType.Int, 4));  
                cmd.Parameters["@PageSize"].Value =pageSize;  
                cmd.Parameters.Add(new SqlParameter("@CurrentPageIndex", SqlDbType.Int, 4));  
                cmd.Parameters["@CurrentPageIndex"].Value = PageIndex;  
      
                DataTable dt = new DataTable();  
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);  
                adapter.Fill(dt);  
      
                con.Close();  
                return dt;  
                  
            }  
      

  2.   

    SqlCommand cmd = new SqlCommand("pagination", con); 
    改为
    SqlCommand cmd = new SqlCommand("usp_OutStudent", con); 
    你的两个参数也相应的改一下就可以了
    WinForm用存储过程分页
      

  3.   

    该简单一点:  SqlConnection con = new SqlConnection(this.ConnectStr());  
      SqlCommand cmd = new SqlCommand("pagination", con);  
      cmd.CommandType = CommandType.StoredProcedure;  
      con.Open();  
      cmd.Parameters.Add(new SqlParameter("@name ", SqlDbType.Char, 10));  
      cmd.Parameters["@name "].Value ="张晓彤"; 
      cmd.Parameters.Add(new SqlParameter("@sex", SqlDbType.Char, 10));  
      cmd.Parameters["@sex"].Value ="女";   cmd.ExecuteNonQuery ();  
      

  4.   

    SqlCommand com=new SqlCommand();
    com.Connection=connection;
    com.CommandText="usp_OutStudent";//是存储过程名称
    com.CommandType=CommandType.StoredProcedure;//CommandType是一枚举类型
      

  5.   

    SqlConnection conn = new SqlConnection(this.ConnectStr());
                conn.Open();
                SqlCommand cmd1 = new SqlCommand();
               
                    cmd1.CommandText = "usp_OutStudent
    ";   //存储过程名
                    cmd1.CommandType = CommandType.StoredProcedure;
                    cmd1.Connection = conn;
                    try
                    {
                        cmd1.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {                    MessageBox.Show(ex.Message);                }
                    finally
                    {                    MessageBox.Show("执行存储成功");
                    
                    
                    }这是没有参数的存储调用,理解了在去试着写带参数的,这样理解的更深
      

  6.   

    楼主是调用带输出参数的存储过程//创建Connection对象,并打开连接
    using (SqlConnection conn = new SqlConnection(connectionString))
    {
        conn.Open();
        //创建Command对象
        using (SqlCommand cmd = conn.CreateCommand())
        {
            cmd.CommandType = CommandType.StoredProcedure;//命令类型是存储过程
            cmd.CommandText = "usp_OutStudent";//调用存储过程名称
            cmd.Parameters.Add("@name", "张三");//创建参数对象,为参数@name 赋值“张三”
            cmd.Parameters.Add("@sex", SqlDbType.Char);
            //参数@sex是输出参数,定义Direction属性值
            cmd.Parameters["@sex"].Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
            Console.WriteLine("性别:{0}", cmd.Parameters["@sex"].Value.ToString());
        }
    }
      

  7.   

    SQL-server中编写存储过程及其调用        在使用Transanct-SQL语言编程过程中,可以将某些多次调用以实现某个特定任务的代码段编写成一个过程,将其保存在数据库中,并由SQL-Server服务器通过过程名调用它们,这些过程就叫做存储过程。       存储过程可以实现一下功能:       1.接收输入参数并以输出参数的格式想调用过程或批处理返回多个值。       2.包含用于在数据库中执行操作(包括调用其他过程)的编程语句。      3.向调用过程或批处理返回状态值,以指明成功或失败(以及失败的原因)。 存储过程分为有参的和无参的: 比如:定义无参构造函数:create proc up_info@startDate datetime,@endDate datetimeasselet orderID,CompanyName,Salename,OrderDatefrom Orders inner join Customer on Orders.CustomerID=Cistomer.CustomerIDSeller.SaleID=Orders.SaleIDwhere (Orders.OrderDate between @startDate and @endDate)go调用构造函数:exec up_info有输出的参存数过程的定义:create proc mp_Customer@CID CHAR(3),@CompanyName CHAR(60) OUTPUT@Address CHAR (40) OUTPUTASSELECT @CompanyName=CompanyName,@Address=ADDRESSFROM Customer cwhere c.CustomerID=@CID调用有参数的存储过程:DECLARE @CompanyName AS CHAR(60)DECLARE @ADDRESS AS CHAR(40)DECLARE @CID AS CHARE(3) exec mp_Customer 'co2'        @CompanyName output,        @Address outputselect @CompanyName as '公司名',@Address as'公司地址'