Determing DataType for a returned DataSet Column

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a DataReader to return my data from the Database and using
GetValue() to retrieve the values. I would like to be able to determine the
Data Type of each ccolumn so as to be able to format Dates. I have found the
GetFieldType function but am having trouble using it. Thanks for any help. My
code is below.

rdr = OracleHelper.ExecuteReader(OraConn, CommandType.StoredProcedure,
"OraPremises.PremDeviceHoldings", ps)

While (rdr.Read())
strLine = ""
For i = 0 To 35

strLine = strLine & rdr.GetValue(i).ToString() & Chr(9)

Next
objStreamWriter.WriteLine(strLine)
End While

REgards
Amelia
 
Hi Amelia,

What trouble are you having with GetFieldType?
 
Almost forgot, you might also try using GetSchemaTable reader's method.
 
Hi Miha,

Thanks so much for your response. It is probably a dumb question but being a
newbie, I am having a bit of trouble.

I couldn't work out what was returned from the SqlDataReader.GetFieldType()
function. I know it is a type but does .Net have Type constants I can compare
too?

In pseudo code, I was wanting to do this:-

If SqlDataReader.GetFieldType(i) = DateTime?? Then
Format(SqlDataReader.GetValue(i),'dd-MM-yyyy')
End If

Thanks Again :0)



Miha Markic said:
Hi Amelia,

What trouble are you having with GetFieldType?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Amelia said:
I am using a DataReader to return my data from the Database and using
GetValue() to retrieve the values. I would like to be able to determine
the
Data Type of each ccolumn so as to be able to format Dates. I have found
the
GetFieldType function but am having trouble using it. Thanks for any help.
My
code is below.

rdr = OracleHelper.ExecuteReader(OraConn, CommandType.StoredProcedure,
"OraPremises.PremDeviceHoldings", ps)

While (rdr.Read())
strLine = ""
For i = 0 To 35

strLine = strLine & rdr.GetValue(i).ToString() &
Chr(9)

Next
objStreamWriter.WriteLine(strLine)
End While

REgards
Amelia
 

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

Back
Top