zoukankan      html  css  js  c++  java
  • 一个简单的数据库操作类

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

  • 相关阅读:
    2012 regional 。。
    joj2443
    java笔记代码实现汉诺塔移动过程和移动次数
    java笔记增加虚拟机内存
    java笔记修改javadoc为中文API信息
    java笔记String类格式化当天日期转换符文档
    java笔记正则表达式的运用(包括电话,邮箱验证等)
    java笔记String类对象解析与运用
    Java笔记IO流的运用
    java笔记BigDecimal的使用
  • 原文地址:https://www.cnblogs.com/studio313/p/269326.html
Copyright © 2011-2022 走看看