日期:2014-05-18  浏览次数:20884 次

GetTopRecord
public static string[] GetTopRecord(OracleConnection conn, OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
{
  string[] strArray = null;
  OracleCommand cmd = new OracleCommand();
  PrepareCommand(cmd, conn, trans, cmdType, cmdText, cmdParms);
  OracleDataReader reader = cmd.ExecuteReader();
  if (reader.Read())
  {
  strArray = new string[reader.FieldCount];
  for (int i = 0; i < reader.FieldCount; i++)
  {
  strArray[i] = reader.IsDBNull(i) ? string.Empty : reader.GetValue(i).ToString();
  }
  }
  reader.Close();
  return strArray;
}

 

 


------解决方案--------------------
不知道你想说你的错误是什么

但是你的代码有问题的

C# code


public static string[] GetTopRecord(OracleConnection conn, OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] cmdParms)
    {
        OracleCommand cmd = null;
        OracleDataReader reader = null;
        try
        {
            string[] strArray = null;
            cmd = new OracleCommand();
            //绑定cmd参数,链接,并且打开数据库链接
            PrepareCommand(cmd, conn, trans, cmdType, cmdText, cmdParms);
            reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                strArray = new string[reader.FieldCount];
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    strArray[i] = reader.IsDBNull(i) ? string.Empty : reader.GetValue(i).ToString();
                }
            }
            return strArray;
        }
        finally
        {
            if (!reader.IsClosed)
            {
                reader.Close();
                reader.Dispose();
                reader = null;
            }
            cmd.Dispose();
            if (conn != null && conn.State != ConnectionState.Closed)
            {
                conn.Close();
                conn.Dispose();
                conn = null;
            }
        }
    }