2011-07-29 45 views
-3
sorgu.CommandText = "select count(*) from mert"; 

我想在if語句中用來計算該查詢中的值。並且,我想要訪問該值。我該如何做?if語句中的計數值

代碼:

OracleConnection conn = new OracleConnection(@"DATA SOURCE=;USER ID=orcl2; Password=123"); 
     conn.Open(); 
     OracleCommand sorgu = new OracleCommand(); 
     sorgu.CommandText = "select * from mert"; 
     sorgu.Connection = conn; 
     OracleDataReader oku = sorgu.ExecuteReader(); 
     while (oku.Read()) 
     { 
      if (oku[0].ToString() == textBox1.Text && oku[1].ToString() == textBox2.Text) 
      { 
       Form2 f = new Form2(); 
       f.ShowDialog(); 
      } 
     } 
     oku.Close(); 

乾杯,

+0

如果僅在Transact SQL中存在。你想要IF/ELSE還是WHERE? – 2011-07-29 12:08:40

+0

@ 0A0D - 我更新了我的問題。 – Selo

回答

0

我從來沒有使用過Oracle數據庫,但每個MSDN這是你需要與你的數據交互:

command.CommandText = "SELECT * FROM OracleTypesTable"; 
    OracleDataReader reader = command.ExecuteReader(); 
    reader.Read(); 
    //Using the Oracle specific getters for each type is faster than 
    //using GetOracleValue. 
    //First column, MyVarchar2, is a VARCHAR2 data type in Oracle Server 
    //and maps to OracleString. 
    OracleString oraclestring1 = reader.GetOracleString(0); 
    Console.WriteLine("OracleString " + oraclestring1.ToString()); 

    //Second column, MyNumber, is a NUMBER data type in Oracle Server 
    //and maps to OracleNumber. 
    OracleNumber oraclenumber1 = reader.GetOracleNumber(1); 
    Console.WriteLine("OracleNumber " + oraclenumber1.ToString()); 

所以,對於每一列,您必須設置一個OracleString,OracleNumber,OracleDateTime,OracleBinary等。相應的積水功能(例如GetOracleString(col))是您如何實際檢索數據。