NET天地

NET天地

导航

统计

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


using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data.OracleClient;
using System.Configuration;
using System.Reflection;

namespace SystemFramework.DAL
{
    
/// <summary>
    
/// All rights reserved
    
/// 数据访问基础类
    
/// 用户可以修改满足自己项目的需要。
    
/// </summary>

    public class DataBaseLayer 
    
{
        
//数据库连接字符串(web.config来配置)
        
//<add key="ConnectionString" value="server=127.0.0.1;database=DATABASE;uid=sa;pwd=" />        
        private string connectionString;
        
public string ConntionString 
        
{
            
get 
            
{
                
return connectionString ; 
            }

            
set 
            
{
                connectionString 
= value;
            }

        }



        
public DataBaseLayer(string strConnect,string dataType)
        
{            
            
this.ConntionString = strConnect;
            
this.DbType = dataType;
        }



        
public DataBaseLayer()
        
{
            
this.connectionString = ConfigurationSettings.AppSettings["ConnectionString"] ;
            
this.dbType = ConfigurationSettings.AppSettings["DataType"] ;
            
//this.connectionString = "data source=192.168.1.43;user id=sa;pwd=sa;database=temphrdb";
            
//this.dbType = "SqlServer";
        }


        
/// <summary>
        
/// 数据库类型 
        
/// </summary>

        private string dbType;
        
public string DbType
        
{
            
get 
            
{
                
if ( dbType == string.Empty || dbType == null )
                
{
                    
return "Access";
                }

                
else
                
{
                    
return dbType;
                }

            }

            
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";
                }

            }
      
        }




        
        
转换参数
        
        
创建 Connection 和 Command

        
执行简单SQL语句

        
执行带参数的SQL语句

        
存储过程操作    


    }

}



  代码下载

posted on 2007-06-06 16:56 闪蓝雨 阅读(...) 评论(...) 编辑 收藏

Powered by .NET Core 3.0 Preview 8 on Linux