c#NET万能数据库访问封装类(ACCESS、SQLServer、Oracle)文库

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

c#NET万能数据库访问封装类(ACCESS、SQLServer、Oracle)文库.txt婚姻是键盘,太多秩序和规则;爱情是鼠标,一点就通。男人自比主机,内存最重要;女人好似显示器,一切都看得出来。usingSystem;usingSystem.Collections;usingSystem.Collections.Specialized;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Data.OleDb;usingSystem.Data.OracleClient;usingSystem.Configuration;usingSystem.Reflection;namespaceSystemFramework.DAL{/**////summary///Allrightsreserved///数据访问基础类///用户可以修改满足自己项目的需要。////summarypublicclassDataBaseLayer{//数据库连接字符串(web.config来配置)//addkey=ConnectionStringvalue=server=127.0.0.1;database=DATABASE;uid=sa;pwd=/privatestringconnectionString;publicstringConntionString{get{returnconnectionString;}set{connectionString=value;}}publicDataBaseLayer(stringstrConnect,stringdataType){this.ConntionString=strConnect;this.DbType=dataType;}publicDataBaseLayer(){this.connectionString=ConfigurationSettings.AppSettings[ConnectionString];this.dbType=ConfigurationSettings.AppSettings[DataType];//this.connectionString=datasource=192.168.1.43;userid=sa;pwd=sa;database=temphrdb;//this.dbType=SqlServer;}/**////summary///数据库类型////summaryprivatestringdbType;publicstringDbType{get{if(dbType==string.Empty||dbType==null){returnAccess;}else{returndbType;}}set{if(value!=string.Empty&&value!=null){dbType=value;}if(dbType==string.Empty||dbType==null){dbType=ConfigurationSettings.AppSettings[DataType];}if(dbType==string.Empty||dbType==null){dbType=Access;}}}转换参数#region转换参数privateSystem.Data.IDbDataParameteriDbPara(stringParaName,stringDataType){switch(this.DbType){caseSqlServer:returnGetSqlPara(ParaName,DataType);caseOracle:returnGetOleDbPara(ParaName,DataType);caseAccess:returnGetOleDbPara(ParaName,DataType);default:returnGetSqlPara(ParaName,DataType);}}privateSystem.Data.SqlClient.SqlParameterGetSqlPara(stringParaName,stringDataType){switch(DataType){caseDecimal:returnnewSystem.Data.SqlClient.SqlParameter(ParaName,System.Data.SqlDbType.Decimal);caseVarchar:returnnewSystem.Data.SqlClient.SqlParameter(ParaName,System.Data.SqlDbType.VarChar);caseDateTime:returnnewSystem.Data.SqlClient.SqlParameter(ParaName,System.Data.SqlDbType.DateTime);caseIamge:returnnewSystem.Data.SqlClient.SqlParameter(ParaName,System.Data.SqlDbType.Image);caseInt:returnnewSystem.Data.SqlClient.SqlParameter(ParaName,System.Data.SqlDbType.Int);caseText:returnnewSystem.Data.SqlClient.SqlParameter(ParaName,System.Data.SqlDbType.NText);default:returnnewSystem.Data.SqlClient.SqlParameter(ParaName,System.Data.SqlDbType.VarChar);}}privateSystem.Data.OracleClient.OracleParameterGetOraclePara(stringParaName,stringDataType){switch(DataType){caseDecimal:returnnewSystem.Data.OracleClient.OracleParameter(ParaName,System.Data.OracleClient.OracleType.Double);caseVarchar:returnnewSystem.Data.OracleClient.OracleParameter(ParaName,System.Data.OracleClient.OracleType.VarChar);caseDateTime:returnnewSystem.Data.OracleClient.OracleParameter(ParaName,System.Data.OracleClient.OracleType.DateTime);caseIamge:returnnewSystem.Data.OracleClient.OracleParameter(ParaName,System.Data.OracleClient.OracleType.BFile);caseInt:returnnewSystem.Data.OracleClient.OracleParameter(ParaName,System.Data.OracleClient.OracleType.Int32);caseText:returnnewSystem.Data.OracleClient.OracleParameter(ParaName,System.Data.OracleClient.OracleType.LongVarChar);default:returnnewSystem.Data.OracleClient.OracleParameter(ParaName,System.Data.OracleClient.OracleType.VarChar);}}privateSystem.Data.OleDb.OleDbParameterGetOleDbPara(stringParaName,stringDataType){switch(DataType){caseDecimal:returnnewSystem.Data.OleDb.OleDbParameter(ParaName,System.Data.DbType.Decimal);caseVarchar:returnnewSystem.Data.OleDb.OleDbParameter(ParaName,System.Data.DbType.String);caseDateTime:returnnewSystem.Data.OleDb.OleDbParameter(ParaName,System.Data.DbType.DateTime);caseIamge:returnnewSystem.Data.OleDb.OleDbParameter(ParaName,System.Data.DbType.Binary);caseInt:returnnewSystem.Data.OleDb.OleDbParameter(ParaName,System.Data.DbType.Int32);caseText:returnnewSystem.Data.OleDb.OleDbParameter(ParaName,System.Data.DbType.String);default:returnnewSystem.Data.OleDb.OleDbParameter(ParaName,System.Data.DbType.String);}}#endregion创建Connection和Command#region创建Connection和CommandprivateIDbConnectionGetConnection(){switch(this.DbType){caseSqlServer:returnnewSystem.Data.SqlClient.SqlConnection(this.ConntionString);caseOracle:returnnewSystem.Data.OracleClient.OracleConnection(this.ConntionString);caseAccess:returnnewSystem.Data.OleDb.OleDbConnection(this.ConntionString);default:returnnewSystem.Data.SqlClient.SqlConnection(this.ConntionString);}}privateIDbCommandGetCommand(stringSql,IDbConnectioniConn){switch(this.DbType){caseSqlServer:returnnewSystem.Data.SqlClient.SqlCommand(Sql,(SqlConnection)iConn);caseOracle:returnnewSystem.Data.OracleClient.OracleCommand(Sql,(OracleConnection)iConn);caseAccess:returnnewSystem.Data.OleDb.OleDbCommand(Sql,(OleDbConnection)iConn);default:returnnewSystem.Data.SqlClient.SqlCommand(Sql,(SqlConnection)iConn);}}privateIDbCommandGetCommand(){switch(this.DbType){caseSqlServer:returnnewSystem.Data.Sq

1 / 29
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功