conn.Close();
}
}
public static DataSet getDataSet(string strConnection,string strSql)
{
if (strConnection==null || strConnection.Length==0)
{
throw new ArgumentNullException( "strConnection" );
}
if (strSql==null || strSql.Length==0)
{
throw new ArgumentNullException( "strSql" );
}
using(SqlConnection conn=new SqlConnection(strConnection))
{
DataSet ds=new DataSet();
conn.Open();
SqlDataAdapter da =new SqlDataAdapter(strSql,conn);
da.Fill(ds);
conn.Close();
return ds;
}
}
public static DataSet getDataSet(SqlConnection conn,string strSql)
{
if (conn==null)
{
throw new ArgumentNullException( "SqlConnection" );
}
if (strSql==null || strSql.Length==0)
{
throw new ArgumentNullException( "strSql" );
}
using(SqlDataAdapter da =new SqlDataAdapter(strSql,conn))
{
DataSet ds=new DataSet();
da.Fill(ds);
conn.Close();
return ds;
}
}
public static int executeNonQuery(string strConnection,string strSql)
{
if (strConnection==null || strConnection.Length==0)
{
throw new ArgumentNullException( "strConnection" );
}
if (strSql==null || strSql.Length==0)
{
throw new ArgumentNullException( "strSql" );
}
using(SqlConnection conn=new SqlConnection(strConnection))
{
SqlCommand sqlCmd=new SqlCommand(strSql,conn);
int i= sqlCmd.ExecuteNonQuery();
conn.Close();
return i;
}
}
public static int executeNonQuery(SqlConnection conn,string strSql)
{
if (conn==null)
{
throw new ArgumentNullException( "SqlConnection" );
}
if (strSql==null || strSql.Length==0)
{
throw new ArgumentNullException( "strSql" );
}
using(SqlCommand sqlCmd=new SqlCommand(strSql,conn))
{
int i=sqlCmd.ExecuteNonQuery();
conn.Close();
return i;
}
}
}
}
3)创建模板列的类(可以创建n种模板列)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Webtest
{
//DropDownList模板列
public class DDListCol : ITemplate
{
string ID;
public DDListCol(string id)
{
this.ID=id;
}
public void InstantiateIn(Control container)
{
DropDownList dpl = new DropDownList();
dpl.ID=this.ID ;
container.Controls.Add(dpl);
}
}
//CheckBox模板列
public class CheckBoxCol : ITemplate
{
string ID;
public CheckBoxCol(string id)
{
this.ID=id;
}
public void InstantiateIn(Control container)
{
CheckBox checkbox = new CheckBox();
checkbox.ID=this.ID ;
container.Controls.Add(checkbox);
}
}
}