473,520 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 ?
May 22 '07 #1
2 21767
Never mind, I found it.
If drSQL.GetFieldType(x) Is GetType(String) Or drSQL.GetFieldType(x) Is
GetType(Date) Then

"fniles" <fn****@pfmail.comwrote in message
news:On**************@TK2MSFTNGP06.phx.gbl...
>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 ?


May 22 '07 #2
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 ?

"fniles" <fn****@pfmail.comwrote in message
news:On**************@TK2MSFTNGP06.phx.gbl...
>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 ?


May 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
26209
by: SD | last post by:
Hi, This is driving me nuts, I have a table that stores notes regarding an operation in an IMAGE data type field in MS SQL Server 2000. I can read and write no problem using Access using the StrConv function and I can Update the field correctly in T-SQL using: DECLARE @ptrval varbinary(16) SELECT @ptrval = TEXTPTR(BITS_data)
4
3135
by: N J | last post by:
Hi, CurrentDb.Execute "Update tblDelayedOrders Set DELAYED = True Where ID = " & Me.txtOrderNumber & ";", dbfailonerror Me.StatusListBox.AddItem "ORDER # " & Me.txtOrderNumber & " MARKED AS DELAYED " & "" & "", 0 When I change Where ID to Where TRACKING (another text field) I get the error Data Type Mismatch in expression critera, or...
0
1692
by: selacika | last post by:
Hi all; My question is about how to get non-font information part of a field of text data type using an sql sentence. Shortly how to get pure info from a text data type field. Example: Value of Field1: {\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset162{\*\fname Arial;}Arial TUR;}{\f1\fnil MS Sans Serif;}}...
1
2245
by: ritu raj shriwastaw | last post by:
I am using window xp and php trait(php3.1,mysql4.2).i have one field is of memo data type and I am unable to retrieve data from that memo data type field. what query I should write?
2
2588
by: nduerr | last post by:
I have a table with pdf files stored in an attachment data type field in a 2007 Access File. I would like to run a query that would select a group out of this table (easy part) then send the pdf file stored in the attachment field in each of the selected records to a specific e- mail address as an attachment to the e-mail. The pdf files can...
0
2731
by: bkberg05 | last post by:
Hi - I currently use Access 2003 and have documents stored in an OLE data type field. I want be able to write a query that contains various other data elements from the table plus the OLE field and export these to an excel file. The query itself shows the document in the OLE field, but when I export the spreadsheet to Excel, the field holding...
1
4447
by: kimsengora | last post by:
Ex. I need to fill in values argument Field1 is text Field2 is image Insert into tbl1 values("'+val1+"','+val2+'") val2 is image like 0x424DFE9D00000000000036000000..................................... I really stuck on this with image values because I have to BCP out my data and and generate the insert statement with value data like...
1
3066
by: littlemaster | last post by:
I am having table in psql it has one field as integer array data type. From rails application I was not able to insert value in that filed. Example: Need to add multiple userid in the name field. create table users(name integer,id serial); a=10 obj-User.new
0
7299
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7559
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3282
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3279
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1646
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
506
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.