存储过程

存储过程分三种:系统存储过程,以sp_开头;扩展存储过程,以XP_开头;用户自定义的存储过程。

存储过程定义:

create proc [存储过程名] --自定义

@[参数] 参数类型,

@[参数] 参数类型 output, --有输入输出

as

(sql 语句)

调用存储过程

declare @id int

exec 存储过程名 参数名 print @id

存储过程的3种传回值:   1)、以Return传回整数   2)、以output格式传回参数   3)、Recordset

vs2005中调用存储过程:

CREATE PROCEDURE AddCar @PayCar varchar(50), @XiuLi varchar(50), @DateTime varchar(50) AS insert into CTable values(@PayCar,@XiuLi,@DateTime) GO
cs代码 con.Open(); com = new SqlCommand("AddCar", con); com.CommandType = CommandType.StoredProcedure;   com.Parameters.AddWithValue("@PayCar", PayCar); com.Parameters.AddWithValue("@XiuLi", XiuLi); com.Parameters.AddWithValue("@DateTime", addtme); com.ExecuteNonQuery(); con.Close();

SqlConnection con= new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);              con.Open();

            SqlDataAdapter  sda = new SqlDataAdapter("存储过程的名字",con);

            sda.SelectCommand.CommandType = CommandType.StoredProcedure;

            DataSet ds = new DataSet();

            strselect.Fill(ds);

            DlstBuycatalog.DataSource =ds;

            DlstBuycatalog.DataBind();

            con.Close();

原文地址:https://www.cnblogs.com/xu3593/p/2821538.html