2010-11-08 63 views
0

我有快速查找這個代碼。它做工精良的SQLCE幫助用C#+的Oracle 11g

SqlCeCommand Cmd; 
Cmd.CommandType = CommandType.TableDirect; 
Cmd.CommandText = "MEN"; 
Cmd.IndexName = "A"; 
Cmd.SetRange(DbRangeOptions.Match, new object[] { R[15].ToString().Trim(), MyDate }, null); 
SqlCeDataReader read = Cmd.ExecuteReader(); 
while (read.Read()) 
{ 
    TmpBAR = read[0].ToString(); 
} 
read.Dispose(); 
if (TmpBAR == "") 
{ 
    //return false; 
} 

我嘗試轉換到Oracle這樣的:

OracleCommand Cmd; 
Cmd.CommandType = CommandType.TableDirect; 
Cmd.CommandText = "MEN"; 
Cmd.IndexName = "A"; 
Cmd.SetRange(DbRangeOptions.Match, new object[] { R[15].ToString().Trim(), MyDate }, null); 
OracleDataReader read = Cmd.ExecuteReader(); 
while (read.Read()) 
{ 
    TmpBAR = read[0].ToString(); 
} 
read.Dispose(); 
if (TmpBAR == "") 
{ 
    //return false; 
} 

,我得到錯誤:

System.Data.OracleClient.OracleCommand' does not contain a definition for 'IndexName' and no extension method 'IndexName' accepting a first argument of type 'System.Data.OracleClient.OracleCommand' could be found (are you missing a using directive or an assembly reference?) 

與此錯誤:

System.Data.OracleClient.OracleCommand' does not contain a definition for 'SetRange' and no extension method 'SetRange' accepting a first argument of type 'System.Data.OracleClient.OracleCommand' could be found (are you missing a using directive or an assembly reference?) 

回答

0

Oracle ADO.NET組件與此不同在SQL CE組件中。如果您需要能夠支持這兩種提供程序,並且您將獲得需要兩個提供程序支持的一組功能,那麼我會建議將所有內容都轉換爲IDbCommand interface。如果您不需要同時支持這兩種提供程序,那麼您只需在Oracle Command對象中找到不同的語法即可完成相同的操作。

2

您將需要使用CommandType.Text並創建相應的SQL語句從表中選擇MEN。您當前使用的功能是特定於SQLCE的,並且不受ORACLE提供程序支持。

你不應該擔心指定索引名,ORACLE SQL優化器會自動選擇合適的指數,假設一個存在。

我也建議你不要使用微軟提供的Oracle供應商,因爲這是在Framework 4.0棄用。 Oracle的ORACLE提供程序非常好。

ODP.NET - http://www.oracle.com/technetwork/database/windows/downloads/index-101290.html