Universal Database Operation Class C # (Repost)

xiaoxiao2021-03-05  24

Class code

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 ();}}}

转载请注明原文地址:https://www.9cbs.com/read-36104.html

New Post(0)