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