3 获取对象IDbDataParameter; IDbCommand参数信息的导出

//oracle版
new OracleParameter();
  
//SqlServer版
new SqlDataParameter();
  
//OleDb版
new OleDbParameter();
  
//Odbc版
new OdbcParameter();

  

   //IDbCommand引用存储过程的参数信息的导出。得到的参数添加到IDbCommand参数集合
    public void DeriverParameters(IDbCommand cmd)
        {
            bool mustCloseConnection = false;
            if (!(cmd is OracleCommand)) 
            {
                //在向方法提供的其中一个参数无效时引发的异常。
                throw new ArgumentException("The command provided is not an OracleCommand instance", "cmd");
            }
            if (cmd.Connection.State != ConnectionState.Open) 
            {
                cmd.Connection.Open();
                mustCloseConnection = true;
            }
            //从在 OracleCommand 中指定的存储过程中检索参数信息并填充指定的 OracleCommand.Parameters 集合
            OracleCommandBuilder.DeriveParameters((OracleCommand)cmd);

            if (mustCloseConnection) 
            {
                //关闭连接
                cmd.Connection.Close();
            }
        }

  

posted @ 2017-10-27 15:35  缘续成  阅读(219)  评论(0编辑  收藏  举报