上面一篇中简单的介绍到了存储过程的查询 接下来是增,删 ,改的实例!
增加的存储过程的代码
create proc [dbo].[InsertUsers]
(
@username varchar(50),
@userpwd varchar(50),
@userphone varchar(50)
)
as
begin
insert into dbo.FMS_Users(userMark,userPassword,userPhone) values(@username,@userpwd,@userphone)
end
调用存储过程的实例
string con = System.Configuration.ConfigurationManager.ConnectionStrings["consql"].ToString(); SqlConnection conn = new SqlConnection(con); conn.Open(); SqlCommand cmd = new SqlCommand("InsertUsers", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@username", SqlDbType.VarChar, 50).Value = "dfsdfsdfs"; cmd.Parameters.Add("@userpwd", SqlDbType.VarChar, 50).Value = "fdffdfds@163.com"; cmd.Parameters.Add("@userphone", SqlDbType.VarChar, 50).Value = "dfds3232"; cmd.ExecuteNonQuery(); //刷新数据 Stroedprocedure();
删除的存储过程的代码
create proc [dbo].[DeleteUsers]
(
@id int
)
as
begin
delete from dbo.FMS_Users where userId=@id
end
调用删除的存储过程的实例
string con = System.Configuration.ConfigurationManager.ConnectionStrings["consql"].ToString(); SqlConnection conn = new SqlConnection(con); conn.Open(); SqlCommand cmd = new SqlCommand("DeleteUsers", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@id", SqlDbType.Int, 32).Value = 23; cmd.ExecuteNonQuery(); //刷新数据 Stroedprocedure();
修改的存储过程的代码
create proc [dbo].[UpdateUsers]
(
@id int,
@email varchar(50)
)
as
begin
update dbo.FMS_Users set userEMail=@email where userId=@id
end
调用修改的存储过程的实例
string con = System.Configuration.ConfigurationManager.ConnectionStrings["consql"].ToString(); SqlConnection conn = new SqlConnection(con); conn.Open(); SqlCommand cmd = new SqlCommand("UpdateUsers", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@id", SqlDbType.Int, 32).Value = 21; cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = "f3dsfdr3234@163.com"; cmd.ExecuteNonQuery(); //刷新数据 Stroedprocedure();
ok 全部完毕 !十一就这样的过去了!如果有哪位需要这个例子的话, 留下邮箱我发给你!希望多多和大家交流!
高人请问这些问题如何解决! 也是关于数据库的调用问题!这是我搜到的一些典型的案例!谢谢
http://topic.csdn.net/t/20060425/13/4712061.html
http://topic.csdn.net/u/20110314/16/115136f2-9d92-45d6-a909-e2b4d3269de2.html
http://www.cnblogs.com/zlhxinxi83/archive/2007/10/16/925978.html
http://topic.csdn.net/u/20110314/16/115136f2-9d92-45d6-a909-e2b4d3269de2.html
http://www.cnblogs.com/zlhxinxi83/archive/2007/10/16/925978.html