exquisite_uae
asked on
count of items or colums of a SQL query using data reader
Greetings,
I need to count the number of colums in a result of a sql query that uses datareader to read the results:
here is the vb code:
Dim conn As New SqlConnection(connectionSt ring)
Dim command As New SqlCommand(strVFD_MO, conn)
command.CommandType = CommandType.Text
conn.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
Dim i As Integer = 0
If reader.HasRows Then
Do While reader.Read()
' the number of colums is unknown, so item id such as reader(0) should not be hard coded
Debug.WriteLine(reader(0), reader(1))
Loop
End If
thanks!!
I need to count the number of colums in a result of a sql query that uses datareader to read the results:
here is the vb code:
Dim conn As New SqlConnection(connectionSt
Dim command As New SqlCommand(strVFD_MO, conn)
command.CommandType = CommandType.Text
conn.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
Dim i As Integer = 0
If reader.HasRows Then
Do While reader.Read()
' the number of colums is unknown, so item id such as reader(0) should not be hard coded
Debug.WriteLine(reader(0),
Loop
End If
thanks!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use thisReader.FieldCount
FieldCount - returns the number of columns in the result set.
GetFieldType(int) - returns the Type of the column.
GetDataTypeName(int) - returns the Name of the back-end database column
type.
GetName(int) - returns the Column Name.
GetFieldType(int) - returns the Type of the column.
GetDataTypeName(int) - returns the Name of the back-end database column
type.
GetName(int) - returns the Column Name.
ASKER
thanks..thats exactly what i need :)