码迷,mamicode.com
首页 > 数据库 > 详细

SQL serve创建与调用存储过程

时间:2016-05-04 17:14:53      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

(1)创建

技术分享

 

2编写存储过程(创建传参的存储过程)存储过程语法网络上很多不在累述

 技术分享

语法解析
Use Person  指定在那个数据库下建立存储过程
if (object_id(‘MyFunction‘, ‘P‘) is not null) 用于避免创建相同的存储过程
    drop proc MyFunction
GO
create proc MyFunction(@name varchar(50),@newsid int)  创建带参的函数
as
begin
Update Info set name = @name where id = @newsid
End
exec MyFunction "王明洋",2     用于测试存储过程
http://www.cnblogs.com/hoojo/archive/2011/07/19/2110862.html
http://www.cnblogs.com/sosoft/p/3535696.html

  

(2)

C#调用

        int ClassID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());

        string CName = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();

        string sqlStr = "update Info set name=‘" + CName + "‘ where id=" + ClassID;

        SqlConnection myConn = GetConnection();

        myConn.Open();

        SqlCommand myCmd = new SqlCommand("MyFunction", myConn);

        myCmd.CommandType = CommandType.StoredProcedure;//开启调用存储过程

        myCmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = CName;//存储过程所需的参数

        myCmd.Parameters.Add("@newsid", SqlDbType.Int).Value = ClassID;//存储过程所需的参数

        myCmd.ExecuteNonQuery();

        myCmd.Dispose();

        myConn.Close();

        GridView1.EditIndex = -1;

        this.bind();

  

 

SQL serve创建与调用存储过程

标签:

原文地址:http://www.cnblogs.com/wangboke/p/5458817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!