码迷,mamicode.com
首页 > 其他好文 > 详细

ADO:用代码调用存储过程

时间:2017-07-09 16:25:12      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:webp   produce   origin   open   bpa   .sql   stc   ring   style   

原文发布时间为:2008-08-02 —— 来源于本人的百度文章 [由搬家工具导入]

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

/// <summary>
/// Produce 的摘要说明
/// </summary>
public class Produce
{
    private SqlConnection conn;
    private SqlCommand cmd;
    private SqlDataAdapter sda;
    private DataSet ds;

    public Produce()
{
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["testConn"].ConnectionString);
        cmd = new SqlCommand();
        sda = new SqlDataAdapter();
        ds = new DataSet();     
}

    public DataTable dt()
    {
        sda.SelectCommand = new SqlCommand("testSelect");
        sda.SelectCommand.CommandType=CommandType.StoredProcedure;
        sda.Fill(ds,"test");
        return ds.Tables["test"];
    }

    public void Update(Int32 id, string name, string banji)
    {
        cmd.CommandText = "testUpdate";
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.AddWithValue("@id", id);
        cmd.Parameters.AddWithValue("@name", name);
        cmd.Parameters.AddWithValue("@class", banji);
        cmd.Parameters.AddWithValue("@Original_id", id);

        cmd.Connection = conn;
        conn.Open();
        cmd.EndExecuteNonQuery();
        conn.Close();
    }
    public void Delete(Int32 id)
    {
        cmd.CommandText = "testDelete";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Original_id", id);
        cmd.Connection = conn;

        conn.Open();
        cmd.EndExecuteNonQuery();
        conn.Close();
    }

}

ADO:用代码调用存储过程

标签:webp   produce   origin   open   bpa   .sql   stc   ring   style   

原文地址:http://www.cnblogs.com/handboy/p/7141568.html

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