根据自己平时的经验写的针对SQLSERVER操作的通用类库
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
namespace Whgw_lc
{
/// <summary>
/// Data 的摘要说明。
/// </summary>
/// <summary>
/// 数据库相关操作类
/// 作者:DarkAngel
/// 时间:2004-9-24
/// </summary>
public class Data
{
/// <summary>
///连接数据库字符串
/// </summary>
protected static string con="data source=10.68.19.203;initial catalog=Whgw;persist security info=False;user id=sa;password=sc2000;workstation id=DARKANGEL;packet size=4096";
/// <summary>
/// 数据库连接对象
/// </summary>
protected System.Data .SqlClient.SqlConnection DataConnection;
/// <summary>
/// SqlDataAdapter对象
/// </summary>
protected System.Data.SqlClient.SqlDataAdapter DataAdapter;
/// <summary>
/// SqlCommand对象
/// </summary>
protected System.Data.SqlClient.SqlCommand DataCommand;
/// <summary>
/// SqlCommandBuilder对象
/// </summary>
protected System.Data.SqlClient.SqlCommandBuilder DataComBuilder;
/// <summary>
/// DataSet对象
/// </summary>
protected System.Data.DataSet DataSet;
/// <summary>
/// DataRow对象
/// </summary>
protected System.Data.DataRow DataRow;
/// <summary>
/// SqlDataReader对象
/// </summary>
protected System.Data.SqlClient.SqlDataReader DataReader;
//protected System.Web.UI.Page mypage;
/// <summary>
///构造函数
/// </summary>
public Data()
{
//
// TODO: 连接数据库参数
//
//con=
DataConnection=DataConn();
}
/// <summary>
/// 数据库连接参数属性
/// </summary>
public string Con
{
get{return con;}
set{con= value;}
}
/// <summary>
/// 建立数据库连接
/// </summary>
/// <returns>返回数据库连接对象</returns>
public SqlConnection DataConn()
{
SqlConnection DataConnection=new SqlConnection(Con);
return DataConnection;
}
/// <summary>
/// 查询结果,返回
/// </summary>
/// <param name="mysql">查询语句</param>
/// <returns>返回datareader</returns>
public SqlDataReader DataQuery(string Sql)
{
DataConnection=DataConn();
DataConnection.Open();
DataReader=null;
DataCommand=new SqlCommand(Sql,DataConnection);
DataReader=DataCommand.ExecuteReader();
return DataReader;
}
/// <summary>
/// 查询结果,返回DataSet
/// </summary>
/// <param name="mysql">查询语句</param>
/// <param name="tabName">表名</param>
/// <returns>DataSet</returns>
public virtual DataSet DataSetQuery(string Sql,string TableName)
{
DataConnection=DataConn();
DataConnection.Open();
DataAdapter=new SqlDataAdapter(Sql,DataConnection);
DataSet=new DataSet();
DataAdapter.Fill(DataSet,TableName);
return DataSet;
}
public DataSet DataSetQuery(DataSet myds,string TableName,string Sql)
{
DataConnection=DataConn();
DataConnection.Open();
DataAdapter=new SqlDataAdapter(Sql,DataConnection);
DataAdapter.Fill(myds,TableName);
return DataSet;
}
/// <summary>
/// 查询结果,返回DataSet,带起始和结束
/// </summary>
/// <param name=&