datareader reader questions

G

Guest

I am trying to use a datareader to retrieve data and set some properties. I
am getting a "Specified method is not supported" error on Line xxx. The data
base is Oracle 9i and the field is a number is Oracle, which will be an
integer.

Code below

The query will retrieve only one record or the datareader will be (empty?).
How do I test for an empty datareader and return a "You're not in the db"
exception?

Thanks for your replies

Mike





Code:

private void getUserRightsFromDB(string userLogin)
{
string SQL;
SQL = "Select ID, USER_ID, USER_NAME, USER_EMAIL, USER_RIGHTS From ";
SQL += "drewermr.TAB_USER_RIGHTS Where USER_LOGIN = '" + userLogin + "'";
//Set command type and string for command object
this.OraCommAssistLogin.CommandType = CommandType.Text;
this.OraCommAssistLogin.CommandText = SQL;
//open db
this.openDB();
dr = this.OraCommAssistLogin.ExecuteReader();
dr.Read();
//retrieve values from database
this.user.DBID = dr.GetInt16(0); // -- Linexxx
this.user.UserID = dr.GetInt16(1);
this.user.FullName = dr.GetString(2);
this.user.EmailAddress = dr.GetString(3);
this.user.UserRights = dr.GetString(4);
this.closeDB();
}
 
W

W.G. Ryan MVP

Whenever you use a DataReader, you want to make sure you walk through the
reader.

First though you can check for rows using the HasRows property immediately
after you call ExecuteReader.

Next, you can walk through each of the records by just using a

while(reader.Read()){
//Process here
}

HTH,

Bill
 
G

Guest

Thanks I got how to handle it if it's empty but what about the "Specified
method is not supported" error? Any idea?

this.user.DBID = dr.GetInt16(0); where this field is a number in Oracle
and user.DBID is a property holding an integer.

Thanks for you help
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top