日期:2013-06-11  浏览次数:20375 次

 

/*************************************************************************************************************
 * 功能:数据库操作相关
 * 作者:FlashICP
 * 时间:2005-7-22
 * **********************************************************************************************************/
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
namespace moban
{
 public class data
 {
  protected static string con="server=[yourserver];database=[yourdata];user id=[your id];password=[youpassword]";
  //数据库字符串
  protected System.Data.SqlClient.SqlConnection DataConnection;
  //数据库连接对象
  protected System.Data.SqlClient.SqlDataAdapter DataAdapter;
  //SqlDataAdapter对象
  protected System.Data.SqlClient.SqlCommand DataCommand;
  //SqlCommand对象
  protected System.Data.SqlClient.SqlCommandBuilder DataComBuilder;
  //SqlCommandBuilder对象
  protected System.Data.DataSet DataSet;
  //DataSet对象
  protected System.Data.DataRow DataRow;
  //DataRow对象
  protected System.Data.SqlClient.SqlDataReader DataReader=null;
  //构造函数
  public data()
  {
   DataConnection=DataConn();
   
  }
  //连接数据库参数
  public string Con
  {
   
   get{return con;}
   set{con= value;}
   
  }
  //数据库连接参数
  public SqlConnection DataConn()
  {
   DataConnection=new SqlConnection(Con); 
   return DataConnection;
   
  }
  //返回数据库连接对象
  public SqlDataReader DataQuery(string Sql)
  {
   Sql=Sql.Replace("--","");
   Sql=Sql.Replace(";","");
   DataConnection=DataConn();
   DataConnection.Open();
   DataReader=null;
   DataCommand=new SqlCommand(Sql,DataConnection);
   DataReader=DataCommand.ExecuteReader();
   DataCommand.Dispose();
   return DataReader;
  }
  //返回DataSet
  public virtual DataSet DataSetQuery(string Sql,string TableName)
  {
   DataConnection=DataConn();
   DataAdapter=new SqlDataAdapter(Sql,DataConnection);
   DataSet=new DataSet();
   DataAdapter.Fill(DataSet,TableName);
   DataAdapter.Dispose();
   DataConnection.Close();
   DataConnection.Dispose();
   return DataSet;
  }
  //返回DataSet
  public DataSet DataSetQuery(DataSet myds,string TableName,string Sql)
  {
   DataConnection=DataConn();
   DataAdapter=new SqlDataAdapter(Sql,DataConnection);
   DataAdapter.Fill(myds,TableName);
   DataConnection.Close();
   DataConnection.Dispose();
   return DataSet;

  }
  //返回DataSet
  public DataSet DataSetQuery(string Sql,string TableName,int StarIndex,int Count)
  {
   DataConnection=DataConn();
   DataConnection.Open();
   DataAdapter=new SqlDataAdapter(Sql,DataConnection);
   DataSet=new DataSet();
   DataAdapter.Fill(DataSet,StarIndex,Count,TableName);
   DataConnecti