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>
/// sqldata 的摘要说明
/// </summary>
public class SqlData
{
private SqlConnection sqlcon;//声明一个SqlConnection对象
private SqlCommand sqlcom;//声明一个SqlCommand对象
private SqlDataAdapter sqldata;//声明一个SqlDataAdapter对象
#region 构造函数
/// <summary>
/// 构造函数,初始化时连接数据库
/// </summary>
public SqlData()
{
sqlcon=new SqlConnection("server=localhost;database=liuyanbu;Uid=sa;Pwd=1314");
sqlcon.Open();//打开链接
}
#endregion
#region 执行SQL语句
///<summary>
///此方法用来执行SQL语句
///</summary>
///<param name="SqlCom">要执行的SQL语句</param>
///<returns></returns>
public bool ExceSQL(String SqlCom)
{
sqlcom = new SqlCommand(SqlCom,sqlcon);
try
{
sqlcom.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
sqlcon.Close();
}
}
#endregion
#region 返回DataSet类型数据
///<summary>
///此方法返回一个DataSet类型数据
///</summary>
///<param name="SqlCom">要执行的SQL语句</param>
///<returns></returns>
public DataSet ExceDS(String SqlCom)
{
try
{
sqlcom = new SqlCommand(SqlCom, sqlcon);
sqldata = new SqlDataAdapter();
sqldata.SelectCommand = sqlcom;
DataSet ds = new DataSet();
sqldata.Fill(ds);
return ds;
}
finally
{
sqlcon.Close();
}
}
#endregion
#region 返回SqlDataReader类型数据
///<summary>
///此方法返回一个SqlDataReader类型数据
///</summary>
///<param name="SqlCom">要执行的SQL语句</param>
///<returns></returns>
public SqlDataReader ExceRead(String SqlCom)
{
sqlcom = new SqlCommand(SqlCom,sqlcon);
SqlDataReader read = sqlcom.ExecuteReader();
return read;
}
#endregion
}