类代码
using System;
using SystemData;
using SystemDataSqlClient;
namespace exchange
{
public class MyDataOp
{
private String StrSql;
private String StrConn;
private SqlConnection Conn;
public MyDataOp(String ss)
{
StrSql = ss;
StrConn = SystemConfigurationConfigurationSettingsAppSettings[ConnectionString];
}
public SqlDataReader CreateReader()
{
Conn=new SqlConnection(StrConn);
SqlCommand Comm=new SqlCommand(StrSqlConn);
ConnOpen();
SqlDataReader MyReader = CommExecuteReader();
return MyReader;
}
public DataSet CreateDataSet()
{
Conn=new SqlConnection(StrConn);
ConnOpen();
SqlDataAdapter Adpt=new SqlDataAdapter(StrSqlConn);
DataSet Ds=new DataSet();
AdptFill(Ds);
return Ds;
}
public SqlCommand ExecuteCommand()
{
Conn=new SqlConnection(StrConn);
SqlCommand Comm=new SqlCommand(StrSqlConn);
ConnOpen();
CommExecuteNonQuery();
return Comm;
}
public void Close()
{
ConnClose();
}
}
}
基本用法
namespace exchange
{
using System;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemData;
using SystemDataSqlClient;
using SystemWeb;
using SystemSecurityCryptography;
public class newjoin : SystemWebUIUserControl
{
protected DataList newjoinlist;
public newjoin()
{
thisInit += new SystemEventHandler(Page_Init);
}
protected void Page_Load(object sender SystemEventArgs e)
{
if(!IsPostBack)
{
LoadData();
}
}
protected void LoadData()
{
String StrSql = select top idleft(corpname) as corpname from crop order by id desc;
MyDataOp mdo = new MyDataOp(StrSql);
DataSet ds = mdoCreateDataSet();
newjoinlistDataSource =dsTables[]DefaultView;
newjoinlistDataBind();
mdoClose();
}
private void Page_Init(object sender EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
thisLoad += new SystemEventHandler(thisPage_Load);
}
}
}