ADO:用代码调用存储过程
Posted 杰的记事本——javascript.shop
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
}
}
以上是关于ADO:用代码调用存储过程的主要内容,如果未能解决你的问题,请参考以下文章