多数据之间的连接操作-集中几个.NET常用的方法(不完整)

using System;
using System.Configuration ;
using ASPNETClassLibrary;
using System.Data;
using System.Data.Common;

namespace Study.Command
{
    
/// <summary>
    
/// Command 的摘要说明。
    
/// </summary>

    public class Command
    
{
        
public Command()
        
{
            
        }

        
        
设置连接数据字符串及数据库类型 connectionString AND dataBaseType connectionString AND dataBaseType

        
/// <summary>
        
/// 设置连接
        
/// </summary>

        public static void SetConnection()
        
{
//                        "SQL"        -- 连接SqlCommand_SQL
//                        "ODBC"        -- 连接到Command_ODBC
//                        "ORACLE"    -- 连接到Command_ORACLE
//                        "OLEDB"        -- 连接到Command_OLEDB
            switch(dataBaseType)
            
{
                
case "SQL":
                    Command_SQL.connectionString 
= connectionString;
                    
break;
                
case "ODBC":
                    Command_ODBC.connectionString 
= connectionString;
                    
break;
                
case "ORACLE":
                    Command_ORACLE.connectionString 
= connectionString;
                    
break;
                
case "OLEDB":
                    Command_OLEDB.connectionString 
= connectionString;
                    
break;
                
default:
                    Command_SQL.connectionString 
= connectionString;
                    
break;
            }
//End switch
        }


        
        
/// <summary>
        
/// 连接数据
        
/// </summary>
        
/// <returns></returns>

        public static IDbConnection GetConnection()
        
{
            SetConnection();
            IDbConnection cn;
            
switch(dataBaseType)
            
{
                
case "SQL":
                    cn 
= Command_SQL.getSqlConnection();
                    
break;
                
case "ODBC":
                    cn 
= Command_ODBC.getOdbcConnection();
                    
break;
                
case "ORACLE":
                    cn 
= Command_ORACLE.getOracleConnection();
                    
break;
                
case "OLEDB":
                    cn 
= Command_OLEDB.getOleDbConnection();
                    
break;
                
default:
                    cn 
= Command_SQL.getSqlConnection();
                    
break;
            }
//End switch
            return cn;
        }



        
/// <summary>
        
/// 设置Command对象
        
/// </summary>
        
/// <returns></returns>

        public static IDbCommand GetCommand()
        
{
            SetConnection();
            IDbCommand cmd ;
            
switch(dataBaseType)
            
{
                
case "SQL":
                    cmd 
= Command_SQL.getSqlCommand();
                    
break;
                
case "ODBC":
                    cmd 
= Command_ODBC.getOdbcCommand();
                    
break;
                
case "ORACLE":
                    cmd 
= Command_ORACLE.getOracleCommand();
                    
break;
                
case "OLEDB":
                    cmd 
= Command_OLEDB.getOleDbCommand();
                    
break;
                
default:
                    cmd 
= Command_SQL.getSqlCommand();
                    
break;
            }
//End switch
            return cmd;
        }


    
        
/// <summary>
        
/// 返回所受影响的行数
        
/// </summary>
        
/// <param name="excuteString"></param>
        
/// <returns></returns>

        public static int ExecuteNoeQuery(string executeString)
        
{
            SetConnection();
            
int count;
            
switch(dataBaseType)
            
{
                
case "SQL":
                    count 
= Command_SQL.ExecuteNonQuery(executeString);
                    
break;
                
case "ODBC":
                    count 
= Command_ODBC.ExecuteNonQuery(executeString);
                    
break;
                
case "ORACLE":
                    count 
= Command_ORACLE.ExecuteNonQuery(executeString);
                    
break;
                
case "OLEDB":
                    count 
= Command_OLEDB.ExecuteNonQuery(executeString);
                    
break;
                
default:
                    count 
= Command_SQL.ExecuteNonQuery(executeString);
                    
break;
            }
//End switch
            return count;
        }



        
/// <summary>
        
/// 返回首先首列的值
        
/// </summary>
        
/// <param name="executeString"></param>
        
/// <returns></returns>

        public static string ExecuteScalar(string executeString)
        
{
            SetConnection();
            
string shouHangShouLei;
            
switch(dataBaseType)
            
{
                
case "SQL":
                    shouHangShouLei 
= Command_SQL.ExecuteScalar(executeString);
                    
break;
                
case "ODBC":
                    shouHangShouLei 
= Command_ODBC.ExecuteScalar(executeString);
                    
break;
                
case "ORACLE":
                    shouHangShouLei 
= Command_ORACLE.ExecuteScalar(executeString);
                    
break;
                
case "OLEDB":
                    shouHangShouLei 
= Command_OLEDB.ExecuteScalar(executeString);
                    
break;
                
default:
                    shouHangShouLei 
= Command_SQL.ExecuteScalar(executeString);
                    
break;
            }
//End switch
            return shouHangShouLei;
        }


    
        
/// <summary>
        
/// 建立一个数据集对象
        
/// </summary>
        
/// <param name="executeString"></param>
        
/// <param name="name"></param>
        
/// <returns></returns>

        public static DataSet GetDataSet(string executeString,string name)
        
{
            SetConnection();
            DataSet dataSet;
            
switch(dataBaseType)
            
{
                
case "SQL":
                    dataSet 
= Command_SQL.getDataSet(executeString,name);
                    
break;
                
case "ODBC":
                    dataSet 
= Command_ODBC.getDataSet(executeString,name);
                    
break;
                
case "ORACLE":
                    dataSet 
= Command_ORACLE.getDataSet(executeString,name);
                    
break;
                
case "OLEDB":
                    dataSet 
= Command_OLEDB.getDataSet(executeString,name);
                    
break;
                
default:
                    dataSet 
= Command_SQL.getDataSet(executeString,name);
                    
break;
            }
//End switch
            return dataSet;
        }

    

        
/// <summary>
        
/// 建立一个数据集对象
        
/// </summary>
        
/// <param name="executeString"></param>
        
/// <returns></returns>

        public static DataSet GetDataSet(string executeString)
        
{
            SetConnection();
            DataSet dataSet;
            
switch(dataBaseType)
            
{
                
case "SQL":
                    dataSet 
= Command_SQL.getDataSet(executeString);
                    
break;
                
case "ODBC":
                    dataSet 
= Command_ODBC.getDataSet(executeString);
                    
break;
                
case "ORACLE":
                    dataSet 
= Command_ORACLE.getDataSet(executeString);
                    
break;
                
case "OLEDB":
                    dataSet 
= Command_OLEDB.getDataSet(executeString);
                    
break;
                
default:
                    dataSet 
= Command_SQL.getDataSet(executeString);
                    
break;
            }
//End switch
            return dataSet;
        }

    
    
        
/// <summary>
        
/// 建立一个Table对象
        
/// </summary>
        
/// <param name="executeString"></param>
        
/// <returns></returns>

        public static DataTable GetDataTable(string executeString)
        
{
            SetConnection();
            DataTable dataTable;
            
switch(dataBaseType)
            
{
                
case "SQL":
                    dataTable 
= Command_SQL.getDataTable(executeString);
                    
break;
                
case "ODBC":
                    dataTable 
= Command_ODBC.getDataTable(executeString);
                    
break;
                
case "ORACLE":
                    dataTable 
= Command_ORACLE.getDataTable(executeString);
                    
break;
                
case "OLEDB":
                    dataTable 
= Command_OLEDB.getDataTable(executeString);
                    
break;
                
default:
                    dataTable 
= Command_SQL.getDataTable(executeString);
                    
break;
            }
//End switch
            return dataTable;
        }


    }

}

 

posted on 2006-09-01 09:40  小土泥  阅读(208)  评论(0编辑  收藏  举报

导航