Chinaunix首页 | 论坛 | 博客
  • 博客访问: 633408
  • 博文数量: 825
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-27 14:19
文章分类

全部博文(825)

文章存档

2011年(1)

2008年(824)

我的朋友

分类:

2008-10-27 14:25:11


  类代码
  
  using System;
  using System.Data;
  using System.Data.SqlClient;
  
  
  namespace exchange
  {
   public class MyDataOp
   {
   private String StrSql;
   private String StrConn;
   private SqlConnection Conn;
   public MyDataOp(String ss)
   {
    StrSql = ss;
    StrConn = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
   }
  
   public SqlDataReader CreateReader()
   {
    Conn=new SqlConnection(StrConn);
    SqlCommand Comm=new SqlCommand(StrSql,Conn);
    Conn.Open();
    SqlDataReader MyReader = Comm.ExecuteReader();
    return MyReader;
   }
   public DataSet CreateDataSet()
   {
    Conn=new SqlConnection(StrConn);
    Conn.Open();
    SqlDataAdapter Adpt=new SqlDataAdapter(StrSql,Conn);
    DataSet Ds=new DataSet();
    Adpt.Fill(Ds);
    return Ds;
   }
   public SqlCommand ExecuteCommand()
   {
    Conn=new SqlConnection(StrConn);
    SqlCommand Comm=new SqlCommand(StrSql,Conn);
    Conn.Open();
    Comm.ExecuteNonQuery();
    return Comm;
   }
   public void Close()
   {
    Conn.Close();
   }
     }
  }
  
  
  
  基本用法
  
  namespace exchange
  {
   using System;
   using System.Web.UI;
   using System.Web.UI.WebControls;
   using System.Data;
   using System.Data.SqlClient;
   using System.Web;
   using System.Security.Cryptography;
  
  
   public class newjoin : System.Web.UI.UserControl
   {
   
   protected DataList newjoinlist;
   public newjoin()
   {
    this.Init += new System.EventHandler(Page_Init);
   }
  
   protected void Page_Load(object sender, System.EventArgs e)
   {
    if(!IsPostBack)
    {
    LoadData();
    }
       }
   
   protected void LoadData()
   {
    String StrSql = "select top 10 id,left(corpname,13) as corpname from crop order by id desc";
    MyDataOp mdo = new MyDataOp(StrSql);
    DataSet ds = mdo.CreateDataSet();
    newjoinlist.DataSource = ds.Tables[0].DefaultView;
    newjoinlist.DataBind();
    mdo.Close();
   }
  
   private void Page_Init(object sender, EventArgs e)
   {
    InitializeComponent();
   }
   private void InitializeComponent()
   {  
    this.Load += new System.EventHandler(this.Page_Load);
   }
   }
  }
【责编:admin】

--------------------next---------------------

阅读(279) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~