关闭

ASP.NET 2.0操作数据库

425人阅读 评论(0) 收藏 举报

 一个ObjectDataSource数据源的数据库操作类:

 

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>
/// sqldb 的摘要说明
/// </summary>

public class sqldb
{
    
private SqlConnection con;
    
private SqlCommand cmd;
    
private SqlDataAdapter sda;
    
private DataSet ds;
    
    
    
    
public sqldb()
    
{
      con
=new SqlConnection(ConfigurationManager.ConnectionStrings["sjkConnectionString"].ConnectionString);
      cmd
=new SqlCommand();
      ds
=new DataSet();
      sda
=new SqlDataAdapter();
    }



    
public DataSet select()
    
{

        sda.SelectCommand
=new SqlCommand("NewSelectCommand", con);
        sda.SelectCommand.CommandType 
= CommandType.StoredProcedure;
         
        sda.Fill(ds,
"sql");
        
return ds;
   
       
    }



    
public void delete(Int32 uid)
    
{
        cmd.CommandText 
= "NewDeleteCommand";
        cmd.CommandType 
= CommandType.StoredProcedure;
        cmd.Connection 
= con;
        cmd.Parameters.AddWithValue(
"@Original_uid",uid);
        con.Open();
        cmd.ExecuteNonQuery();
 


    }


   
// public void insert(string username, string usrepass)
   
// {
   
//     cmd.CommandType = CommandType.StoredProcedure;
   
//     cmd.Connection = con;
   
//     cmd.CommandText = "NewDeleteCommand";
   
//     cmd.Parameters.AddWithValue(@username,usernam);
   
//     cmd.Parameters.AddWithValue(@userpass,userpass);
   
//     con.Open();
   
//     cmd.ExecuteNonQuery();
   
//     con.Close();

   
//}


    
public void update(string username, string userpwd, Int32 uid)
    
{
       
        cmd.CommandText 
= "NewUpdateCommand";
        cmd.CommandType 
= CommandType.StoredProcedure;
        cmd.Connection 
= con;
        cmd.Parameters.AddWithValue(
"@username",username);
        cmd.Parameters.AddWithValue(
"@userpwd",userpwd);
        cmd.Parameters.AddWithValue(
"@Original_uid",uid);
        cmd.Parameters.AddWithValue(
"@uid",uid);
        con.Open();
        cmd.ExecuteNonQuery();
     

    }


}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:45727次
    • 积分:874
    • 等级:
    • 排名:千里之外
    • 原创:43篇
    • 转载:7篇
    • 译文:0篇
    • 评论:4条
    文章分类
    最新评论
    ASP