Help with oracle reader (vsnet2005)

T

Tony

Using vsnet2005

In the code below, I don't really need the two commented out dateTime
variables there, but my question is, if the fields in oracle is null,
why would it not just set the variable to null?
I get an exception "No data exists for the row or column."

Also, the Status field (which is defined as char in the table)
contains a space in the 1 record in the table so far, returns an
exception
"Specified method is not supported."
when reading it with the commented out reader.getchar line below
but when I use get value and convert it to char, all is well.

How os the specified method not supported?


public partial class Form1 : Form
{

Int32 iTRANS_SFTP_ID;
DateTime dtDATE_TIME_STAMP;
DateTime dtDATE_TIME_PROCESSED;
DateTime dtDATE_TIME_COMPLETED;
string strPROGRAM_NAME;
char chrSTATUS;
string strLOCAL_FILE_PATH;
string strLOCAL_FILE_NAME;
string strREMOTE_FILE_PATH;
string strREMOTE_FILE_NAME;
Int32 iREMOTE_SERVER_ID;
............

public void ReadData(string connectionString)
{
string queryString = ("SELECT TRANS_SFTP_ID,
DATE_TIME_STAMP, DATE_TIME_PROCESSED, " +

"DATE_TIME_COMPLETED,PROGRAM_NAME,STATUS, LOCAL_FILE_PATH," +
"LOCAL_FILE_NAME, REMOTE_FILE_PATH,
" +
"REMOTE_FILE_NAME,REMOTE_SERVER_ID
FROM trans_sftp");

MessageBox.Show(queryString);
using (OracleConnection connection = new
OracleConnection(connectionString))
{
OracleCommand command = new OracleCommand(queryString,
connection);
connection.Open();
OracleDataReader reader;
reader = command.ExecuteReader();



while (reader.Read())
{
iTRANS_SFTP_ID = (reader.GetInt32(0));
dtDATE_TIME_STAMP = (reader.GetDateTime(1));
//dtDATE_TIME_PROCESSED = (reader.GetDateTime(2));
//dtDATE_TIME_COMPLETED = (reader.GetDateTime(3));
strPROGRAM_NAME = (reader.GetString(4));
// chrSTATUS = (reader.GetChar(5));
chrSTATUS = (Convert.ToChar(reader.GetValue(5)));
strLOCAL_FILE_PATH = (reader.GetString(6));
strLOCAL_FILE_NAME = (reader.GetString(7));
strREMOTE_FILE_PATH = (reader.GetString(8));
strREMOTE_FILE_NAME = (reader.GetString(9));
iREMOTE_SERVER_ID = (reader.GetInt32(10));




Thanks in advance for any assistance.!!
I plan on converting each variable to an array to hold multiple
records if needed, but I'm working on the simplest form of the app to
start with,

Tony!
 
J

Jon Skeet [C# MVP]

Tony said:
In the code below, I don't really need the two commented out dateTime
variables there, but my question is, if the fields in oracle is null,
why would it not just set the variable to null?

DateTime variables can't be null, because DateTime is a value type. You
need to check whether or not the value is null first, and work out some
appropriate value to use if the field is null.

If you're using .NET 2.0, you might want to think about using a
nullable DateTime. See
http://pobox.com/~skeet/csharp/csharp2/nullable.html
for more information.
I get an exception "No data exists for the row or column."

Also, the Status field (which is defined as char in the table)
contains a space in the 1 record in the table so far, returns an
exception
"Specified method is not supported."
when reading it with the commented out reader.getchar line below
but when I use get value and convert it to char, all is well.

I suggest you just use the version which works then (although I'd just
cast to char rather than calling Convert.ToChar, myself).
How os the specified method not supported?

It presumably just isn't. A provider can choose not to support all
methods.
 
W

WenYuan Wang [MSFT]

Hi Tony,
Thanks for Jon's suggestion.

Have you resolved this issue so far? If you met any further issue, please
feel free to post it here and we will follow up.

Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
 
T

Tony

Hi Tony,
Thanks for Jon's suggestion.

Have you resolved this issue so far? If you met any further issue, please
feel free to post it here and we will follow up.

Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support


Yes, all is good.,,. Sometimes the simplest resolution is the best.

Thanks for the assist folks :)

Tony!
 

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