• ADO:用代码调用存储过程


    原文发布时间为: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();
        }

    }

  • 相关阅读:
    初学Cocos2dx
    炸弹人NABCD分析
    求二维整数数组中最大联通子数组的和
    大道之简读书笔记1
    求首位相连二维数组最大子矩阵的和
    求首位相连一维数组最大子数组的和
    求二维数组最大子数组的和
    程序员修炼之道读后感3
    电梯调度需求分析
    课堂作业第四周课上作业二
  • 原文地址:https://www.cnblogs.com/handboy/p/7141568.html
Copyright © 2020-2023  润新知