类代码 using System; using System.Data; using System.Data.SqlClient; namespace exchange { public class MyDataOp { private String StrSql; private String StrConn; private SqlConnection Conn; public MyDataOp(String ss) { StrSql = ss; StrConn = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]; } public SqlDataReader CreateReader() { Conn=new SqlConnection(StrConn); SqlCommand Comm=new SqlCommand(StrSql,Conn); Conn.Open(); SqlDataReader MyReader = Comm.ExecuteReader(); return MyReader; } public DataSet CreateDataSet() { Conn=new SqlConnection(StrConn); Conn.Open(); SqlDataAdapter Adpt=new SqlDataAdapter(StrSql,Conn); DataSet Ds=new DataSet(); Adpt.Fill(Ds); return Ds; } public SqlCommand ExecuteCommand() { Conn=new SqlConnection(StrConn); SqlCommand Comm=new SqlCommand(StrSql,Conn); Conn.Open(); Comm.ExecuteNonQuery(); return Comm; } public void Close() { Conn.Close(); } } }
|