欢迎来到天天文库
浏览记录
ID:51889185
大小:76.00 KB
页数:9页
时间:2020-03-18
《SQL数据库操作基础类.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、usingSystem;usingSystem.Configuration;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Collections;namespaceMyCorporation.DepartMe^.DataBase{III///通川数据库类IIIpublicclassDataBase{privatestringConnStr=null;publicDataBase(){ConnStr=Configurat
2、ionsettings.AppSettings[HConnStrM];)publicDataBase(stringStr){try{this.ConnStr=Str;}catch(Exceptionex){throwex;)}IIIIII返冋connection对象IIIIIIpublicSqlConnectionReturnConn(){SqlConnectionConn=newSqlConnection(ConnStr);Conn.Open(
3、);returnConn;}publicvoidDispose(SqlConnectionConn)if(Conn!=null)Conn.Close();Conn.Dispose();)GC.CollectO;}IIIIII运行SQL语句IIIIIIpublicvoidRunProc(stringSQL){SqlConnectionConn;Conn=newSqlConnection(ConnStr);Conn.Open();SqlC
4、ommandCmd;Cmd=CreateCmd(SQL,Conn);try{Cmd.ExecuteNonQueryO;)catch{thrownewException(SQL);)Dispose(Conn);return;}III///运行SQL语句返回DataReaderIIIIIIIIISqlDataReader对象.publicSqlDataReaderRunProcGetReader(st
5、ringSQL){SqlConnectionConn;Conn二newSqlConnection(ConnStr);Conn.Open();SqlCommandCmd;Cmd=CreateCmd(SQL,Conn);SqlDataReaderDr;try{Dr=Cmd.ExecuteReader(CommandBehavior.Default);)catchthrownewException(SQL);}//Dispose(Conn);returnDr;}III///工成Command对彖III6、mmary>IIIIII///Corm)publicSqlCommandCreateCmd(stringSQL,SqlConnection{SqlCommandCmd;Cmd=newSqlCommand(SQL,Conn);returnCmd;}IIIIII生成Command对象///IIIIII<7、returnsx/returns>publicSqlCommandCreateCmd(stringSQL){SqlConnectionConn;Conn=newSqlConnection(ConnStr);Conn.Open();SqlCommandCmd;Cmd=newSqlCommand(SQL,Conn);returnCmd;)III///返冋ad叩忙r对彖IIIIIIIIII8、IIpublicSqlDataAdapterCreateDa(stringSQL)SqlConnectionConn;Conn=newSqlConnection(ConnStr);Conn.Open();SqlDataAdapterDa;Da=newSqlDataAdapter(S
6、mmary>IIIIII///Corm)publicSqlCommandCreateCmd(stringSQL,SqlConnection{SqlCommandCmd;Cmd=newSqlCommand(SQL,Conn);returnCmd;}IIIIII生成Command对象///IIIIII<
7、returnsx/returns>publicSqlCommandCreateCmd(stringSQL){SqlConnectionConn;Conn=newSqlConnection(ConnStr);Conn.Open();SqlCommandCmd;Cmd=newSqlCommand(SQL,Conn);returnCmd;)III///返冋ad叩忙r对彖IIIIIIIIII
8、IIpublicSqlDataAdapterCreateDa(stringSQL)SqlConnectionConn;Conn=newSqlConnection(ConnStr);Conn.Open();SqlDataAdapterDa;Da=newSqlDataAdapter(S
此文档下载收益归作者所有