using System;
using System.Data;
using System.Data.SqlClient;namespace Core
{
/// <summary>
/// DbObject 的摘要说明。
/// </summary>
public abstract class DbObject
{
protected SqlConnection Connection;
private string connectionString;
public DbObject( string newConnectionString )
{
connectionString = newConnectionString;
Connection = new SqlConnection( connectionString );
}
protected string ConnectionString
{
get 
{
return connectionString;
}
}
private SqlCommand BuildIntCommand(string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = BuildQueryCommand( storedProcName, parameters ); command.Parameters.Add( new SqlParameter ( "ReturnValue",
SqlDbType.Int,
4, /* Size */
ParameterDirection.ReturnValue,
false, /* is nullable */
0, /* byte precision */
0, /* byte scale */
string.Empty,
DataRowVersion.Default,
null )); return command;
}

private SqlCommand BuildQueryCommand(string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = new SqlCommand( storedProcName, Connection );
command.CommandType = CommandType.StoredProcedure; foreach (SqlParameter parameter in parameters)
{
command.Parameters.Add( parameter );
} return command; }
protected int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected )
{
int result; Connection.Open();
SqlCommand command = BuildIntCommand( storedProcName, parameters );
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
Connection.Close();
return result;
}
protected SqlDataReader RunProcedure(string storedProcName, IDataParameter[] parameters )
{
SqlDataReader returnReader; Connection.Open();
SqlCommand command = BuildQueryCommand( storedProcName, parameters );
command.CommandType = CommandType.StoredProcedure; returnReader = command.ExecuteReader(CommandBehavior.CloseConnection);
//Connection.Close();
return returnReader;
}
protected DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName )
{
DataSet dataSet = new DataSet();
Connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = BuildQueryCommand( storedProcName, parameters );
sqlDA.Fill( dataSet, tableName );
Connection.Close(); return dataSet;
}
protected SqlDataAdapter RunProcedure(string storedProcName, IDataParameter[] parameters, int Sql )
{
// DataSet dataSet = new DataSet();
Connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = BuildQueryCommand( storedProcName, parameters );
// sqlDA.Fill( dataSet, tableName );
Connection.Close(); return sqlDA;
}

protected void RunProcedure(string storedProcName, IDataParameter[] parameters, DataSet dataSet, string tableName )
{
Connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = BuildIntCommand( storedProcName, parameters );
sqlDA.Fill( dataSet, tableName );
Connection.Close();
}
}
}

解决方案 »

  1.   

    把sql都换成oracle
    编译一下
      

  2.   

    只要改换成oracle 就行吗?
      

  3.   

    我已经做过了:  整页的SQL 都替换成 ORACLE 就 OK 了!
      

  4.   

    using System.Data.OracleClient;
    没这个引用啊 
      

  5.   


    SqlConnection 改为 OleDbConnection
    Sql....改为OleDb...就ok 了!
      

  6.   

    using System.Data.OracleClient;
    没这个引用啊 
    -----------------------------------------------
    Oracle名空间没有随编译器提供,可在微软站点下载。
      

  7.   

    建立使用OleDb.
    虽然会比直接使用SQL或Oracel慢一点点,但它可以在不修改太多代码的表况下,访问Access,Excel,SQL Server, Oracle等多种数据库
      

  8.   

    同意楼上的,如果你的系统后台数据库类型经常变动的话还是用OleDb好点!!!
    如果不是,可以针对性使用,如SQL Server就引用SqlClint,如此类推!!至于Oracle的话,要首先在项目的引用里添加引用,才可以在代码中using System.Data.OracleClient
      

  9.   

    using System.Data.OracleClient;
    没这个引用啊 
    -----------------------------------------------
    Oracle名空间没有随编译器提供,可在微软站点下载。
    我装了Oracle后 在添加引用里有个Oracle.DataAccess.dll 是这个吗
      

  10.   

    另外问下我如果用OLEDB的话是不是把SQL都改位OLEDB就行了呢?
    在web.config里 如何写连接串呢