0

I am new to Oracle and trying to get data from a Oracle DB. Following is my code. No error is showing in the console. But in the code will not enter inside the while loop. As I am new to this somebody please help me to solve this issue ?

public void Login()
        {
            using (OracleConnection connection = new OracleConnection())
            {
                connection.ConnectionString = ConnectionString;

                try
                {
                    LogManager.Info("inside login");
                    connection.Open();
                    OracleCommand cmd = connection.CreateCommand();
                    cmd.Connection = connection;

                    string sql = "select ID from APRV_EMPLOYEE where USERNAME = :username ";
                    LogManager.Info("sql" + sql);
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    cmd.BindByName = true;
                    cmd.Parameters.Add(":username", OracleDbType.NVarchar2).Value = "admin";
                    IDataReader reader = cmd.ExecuteReader();

                    LogManager.Info("Inside DatabaseManager::hasrows");
                    while (reader.Read())
                    {
                        LogManager.Info("Inside DatabaseManager::read" + reader.GetString(1));
                        LogManager.Info("Inside DatabaseManager::read2" + reader.GetString(reader.GetOrdinal("ID")));

                    }

                    reader.Dispose();
                    cmd.Dispose();
                }
                catch (Exception ex)
                {
                    LogManager.Error("Inside DatabaseManager::Login " + ex.Message);
                }
            }
        }

Please help me Thanks in advance

4

1 回答 1

1

查看文档,这是它应该如何工作的

string sql = "select ID from APRV_EMPLOYEE where USERNAME = :1 ";
LogManager.Info("sql" + sql);
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
// cmd.BindByName = true;
cmd.Parameters.Add("username", OracleDbType.NVarchar2).Value = "admin";
IDataReader reader = cmd.ExecuteReader();
于 2013-07-25T16:47:56.940 回答