请问高手asp.net中如何调用存储过程

解决方案 »

  1.   

    string connstring = @"Data Source=localhost;Initial Catalog=Northwind;uid=sa;pwd=";
            SqlConnection conn = new SqlConnection(connstring);
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;//设置cmd的类型为存储过程
            cmd.CommandText = "CustOrderHist";
            cmd.Connection = conn;        SqlParameter pCustomerID = new SqlParameter();
            pCustomerID.ParameterName = "@CustomerID";
            pCustomerID.SqlDbType = SqlDbType.NChar;
            pCustomerID.Value = "ALFKI";        cmd.Parameters.Add(pCustomerID);
    CustOrderHist:存储过程名称,@CustomerID存储过程中的参数。 
      

  2.   

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString()); 
    conn.Open(); 
    SqlCommand MyCommand = new SqlCommand("", conn); 
    MyCommand.CommandType = CommandType.StoredProcedure; 
    MyCommand.Parameters.Add(new SqlParameter("@a", SqlDbType.Int)); 
    MyCommand.Parameters["@a"].Value = 20; 
    MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int)); 
    MyCommand.Parameters["@b"].Value = 20; 
    MyCommand.Parameters.Add(new SqlParameter("@c", SqlDbType.Int)); 
    MyCommand.Parameters["@c"].Direction = ParameterDirection.Output; 
    MyCommand.ExecuteNonQuery(); 
    Response.Write(MyCommand.Parameters["@c"].Value.ToString());