How can I check the data type of a field in the DataReader ?

F

fniles

I am using VB.NET 2005 and SQLDataReader.
How can I check the data type of a field in the DataReader ? Thank you.

Dim cmdSQL As SqlClient.SqlCommand
Dim drSQL As SqlClient.SqlDataReader

sSQL = "select * from " & sTableName
cmdSQL = New SqlClient.SqlCommand
With cmdSQL
.Connection = m_Connection
.CommandText = sSQL
End With
drSQL = cmdSQL.ExecuteReader()
iFieldCnt = drSQL.FieldCount
Do While drSQL.Read
For x = 0 To iFieldCnt - 1
If drSQL.Item(x).GetType("system.string") Then ----> i want to
check of the data type of this column is string, how can I do that ?
Otherwise, how can I check the data type of this column ?
 
F

fniles

Never mind, I found it.
If drSQL.GetFieldType(x) Is GetType(String) Or drSQL.GetFieldType(x) Is
GetType(Date) Then
 
F

fniles

Now, I seem not to be able to find how to find a data type of a field in a
DataSet.
Dim aRow As DataRow()

m_cmdSQL = New SqlClient.SqlCommand
With m_cmdSQL
.Connection = adoCon
.CommandText = sSQL
End With
m_daSQL = New SqlClient.SqlDataAdapter
m_dsSQL = New DataSet
m_daSQL.SelectCommand = m_cmdSQL
m_daSQL.Fill(m_dsSQL)
for arow in m_dsSQL.Tables(0).rows
--> How do you find the data type of column 1, 2, etc ?
 
B

Buntha Khin

This sample I hope can help you..
In vb.net

If (datatablename.Columns(colname).DataType Is GetType(Double)) Then

'Write your condition here
End If


Buntha

Thanks
 
B

Buntha Khin

This sample I hope can help you..
In vb.net

If (datatablename.Columns(colname).DataType Is GetType(Double)) Then

'Write your condition here
End If


Buntha

Thanks
 

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