(最简单的)在VS中调用存储过程
public void InsertAuthor(string Id, string LName)
{
SqlConnection con = new SqlConnection("server=.;database=test;uid=sa;pwd=12345;");
con.Open();
SqlCommand myCommand = new SqlCommand("InsertAuthor",con);//指定存储过程
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterId = new SqlParameter("@Id",SqlDbType.VarChar,11);
parameterId.Value = Id;
myCommand.Parameters.Add(parameterId);
SqlParameter parameterLName = new SqlParameter("@LName",LName);
myCommand.Parameters.Add(parameterLName);
myCommand.ExecuteNonQuery();
Response.Write("插入成功!");
}
我表的结构如下:
Id varchar 11
LName varchar 40
存储过程如下:
CREATE Procedure InsertAuthor
(
@Id varchar(11),
@LName varchar(40)
)AS
INSERT INTO authors
(
Id,
Lname
)VALUES
(
@Id ,
@LName
)
GO
这是最近学存储过程的一点笔记,希望对大家有帮助!