• SQL serve创建与调用存储过程


    (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();
    

      

     

  • 相关阅读:
    Spring 基础学习
    Swagger basics (one)
    Handsontable Basics V7(one)
    JavaScript 对象
    CSS 基础总结
    Shell Programming(three)
    Shell Programming(two)
    Shell Programming(one)
    HTML标签总结
    jQuery 基础
  • 原文地址:https://www.cnblogs.com/wangboke/p/5458817.html
Copyright © 2020-2023  润新知