查询oracle 报错
独孤正龙 2017-11-27 07:08:49 异常信息System.InvalidCastException: Specified cast is not valid.
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i)
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValues(Object[] values)
at System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values)
at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at Oracle.ManagedDataAccess.Client.OracleDataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at Oracle.ManagedDataAccess.Client.OracleDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
代码如下:
try
{
sql = sql.Replace("P_start", (index * number+1).ToString()).Replace("Pend", ((index+1) * number).ToString());
OpenConn();
LogHelper.Write(string.Format("ExcuteSelectSql== {0} ", sql));
System.Data.DataSet ds = new DataSet();
OracleDataAdapter Ada = new OracleDataAdapter(sql, conn);
Ada.AcceptChangesDuringFill = true;
Ada.AcceptChangesDuringUpdate = true;
if (tableName == "") tableName = "oracle_data";
Ada.Fill(ds, tableName);
LogHelper.Write(string.Format("ExcuteSelectSql==table Name :{0},rows: {1} ", tableName, ds.Tables[0].Rows.Count));
CloseConn(conn);
return ds.Tables[0];
}
catch (Exception ex)
{
LogHelper.Write("ExcuteSelectSql:" + ex.ToString());
CloseConn(conn);
return null;
}
并不是所有的sql 都报错,,,有写sql 执行正常,但是所有的sql 在plsql中执行正常