在C#中创建sql的存储过程方法之一

    技术2022-05-20  41

        

    using System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;创建存储过程代码public partial class StoredProcedures{        [SqlProcedure]        public static void StoredProcedure1    (SqlString id, SqlString title)    {

     

           SqlConnection con = new SqlConnection("SqlClr Connection=true");        con.Open();        SqlCommand cmd = new SqlCommand();        cmd.Connection = con;        cmd.CommandText = "update Books set Title=@p1 where ID=@p2";        SqlParameter p1 = new SqlParameter("@p1", title);        SqlParameter p2=new SqlParameter("@p2",id);        cmd.Parameters.Add(p1);        cmd.Parameters.Add(p2);        int i = cmd.ExecuteNonQuery();        con.Close();        SqlContext.Pipe.Send(i.ToString());    }    public void adf()    {        StoredProcedure1("4939", "HELLO WORD");    }

     

    };调用代码 :public partial class _Default : System.Web.UI.Page {    protected void Page_Load(object sender, EventArgs e)    {        StoredProcedures.StoredProcedure1("4939", "你好");            }}


    最新回复(0)