Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

problem reading data from OleDbDataReader

$
0
0
I am writing an application that has to manage a small database. one of the tasks of the application is that it has to retrieve the information of a company. I tried reading the data into my List(Of String) but somehow it keeps claiming not to return any data. But when I use the debugger, I see that it has 9 fields in it (visibleFields property)
this is the code I am using for the moment:
Public Function getFirmaDetails(ByVal firma As String) As List(Of String)
        Dim Query As String = "SELECT tblplatenfirma.fldaanspreking, tblplatenfirma.fldtav, tblplatenfirma.fldnaam, tblplatenfirma.fldstraat, tblplatenfirma.fldpost, tblplatenfirma.fldgem, tblplatenfirma.fldtel, tblplatenfirma.fldfax, tblplatenfirma.fldreknr FROM tblplatenfirma WHERE (((tblplatenfirma.fldnaam)=""" + firma + """));"
        Dim connection As New OleDbConnection(My.Settings.Oefen2010__Peeters_ConnectionString)
        connection.Open()
        Dim command As New OleDbCommand(Query, connection)
        Dim reader As OleDbDataReader = command.ExecuteReader()
        If reader.HasRows Then
            Dim results As List(Of String) = New List(Of String)
            For i = 0 To reader.FieldCount - 1
                'now read the data in the database
                results.Add(reader(i))
            Next
            Return results
        Else
            Return Nothing
        End If
    End Function

(please ignore the huge SQL injection security hole ;) )
the strange thing is, that with this code I am able to retrieve the names of the fields:
Public Function getFirmaDetails(ByVal firma As String) As List(Of String)
        Dim Query As String = "SELECT tblplatenfirma.fldaanspreking, tblplatenfirma.fldtav, tblplatenfirma.fldnaam, tblplatenfirma.fldstraat, tblplatenfirma.fldpost, tblplatenfirma.fldgem, tblplatenfirma.fldtel, tblplatenfirma.fldfax, tblplatenfirma.fldreknr FROM tblplatenfirma WHERE (((tblplatenfirma.fldnaam)=""" + firma + """));"
        Dim connection As New OleDbConnection(My.Settings.Oefen2010__Peeters_ConnectionString)
        connection.Open()
        Dim command As New OleDbCommand(Query, connection)
        Dim reader As OleDbDataReader = command.ExecuteReader()
        If reader.HasRows Then
            Dim results As List(Of String) = New List(Of String)
            For i = 0 To reader.FieldCount - 1
                'now read the data in the database
                Console.WriteLine(reader.GetName(i))
            Next
            Return results
        Else
            Return Nothing
        End If
    End Function

any help would be appreciated, if you have more questions just ask.
thanks in advance!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>