--------------------------------
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>
/// Summary description for sqlConn
/// </summary>
public class sqlConn
{
public sqlConn()
{
//
// TODO: Add constructor logic here
//
}
//connstring:连接数据库的字符串,只要修改它就可以连接不同的数据库
public static string connstring = "server=.;database=pubs;uid=sa;pwd=";
//这里根据SQL语句生成一个DataSet,DataSet支持分页功能!
public static DataSet GreatDs(string sql)
{
SqlDataAdapter Dar = new SqlDataAdapter(sql, connstring);
DataSet ds = new DataSet();
Dar.Fill(ds);
return ds;
}
//这里根据SQL语句生成一个SqlDataReader,SqlDataReader不支持分页功能!
public static SqlDataReader GreatDR(string sql)
{
SqlConnection conn = new SqlConnection(connstring);
conn.Open();
SqlCommand cmd=new SqlCommand(sql,conn);
SqlDataReader dr = cmd.ExecuteReader();
return dr;
conn.Close();
}
//这里执行一SQL语句
public static void DoSql(string sql)
{
SqlConnection conn = new SqlConnection(connstring);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}