我使用以下查询从Oracle all_objects
视图访问数据。从Oracle SQL Developer尝试相同的工作时,它可以正常工作,并且从C#代码中获取任何数据都不会。
SELECT OBJECT_NAME,OBJECT_TYPE,CREATED,LAST_DDL_TIME
FROM sys.all_objects
where object_type='TABLE'
AND OWNER='SYS'
AND LAST_DDL_TIME between to_date('01/01/2013','DD/MM/YYYY')
and to_date('01/10/2016','DD/MM/YYYY')
如果我在没有任何过滤器的情况下使用以下查询,它在Oracle和C#中都可以正常工作......
SELECT OBJECT_NAME,OBJECT_TYPE,CREATED,LAST_DDL_TIME FROM sys.all_objects
知道它为什么不起作用?
以下是getDatSet函数中传递的示例值,日期是从c#DateTimepicker
中选择的strFromDate - {2/15/2012 12:00:00 AM} strToDate - {11/15/2016 2:31:48 PM}
public DataSet GetDataSet(DateTime strFromDate, DateTime strToDate, List<string> strObjects)
{
OracleCommand objCmd;
OracleDataAdapter objDA;
DataSet objDS;
string StrSqlObjects = string.Empty; ;
try
{
StrSqlObjects += " SELECT OBJECT_NAME,OBJECT_TYPE,CREATED,LAST_DDL_TIME FROM sys.all_objects where ";
StrSqlObjects += " LAST_DDL_TIME between to_date(:startdate,'DD/MM/YYYY') and to_date(:enddate,'DD/MM/YYYY')";
objCmd = new OracleCommand(StrSqlObjects);
objCmd.Connection = m_Conn;
objCmd.Parameters.Clear();
objCmd.Parameters.Add("startdate", strFromDate);
objCmd.Parameters.Add("enddate",strToDate);
objDA = new OracleDataAdapter();
objDA.SelectCommand = objCmd;
var oracleCommandBindByNameProperty = objCmd.GetType().GetProperty("BindByName");
oracleCommandBindByNameProperty.SetValue(objCmd, true, null);
objDS = new DataSet();
objDS.Tables.Add("AllChange");
objDA.Fill(objDS, "Allchange");
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine("Error GetDataSet " + e.Message);
throw e;
}
finally
{
CloseConnection();
}
return objDS;
}