在if语句中计算值

时间:2011-07-29 12:06:54

标签: if-statement count

sorgu.CommandText = "select count(*) from mert";

我想在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();

干杯,

1 个答案:

答案 0 :(得分: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());

因此,对于每列,您必须设置OracleStringOracleNumberOracleDateTimeOracleBinary等相应的功能(例如GetOracleString(col) )是你实际检索数据的方式。