Problem with DataReader

Problem with DataReader

Postby Zero-G. » Tue 12 Jun 2007 13:42

Hey
I have a "thinking" problem...
I use your latest Building of mySQLDirect.NET with the following code:
Code: Select all
        Me.Cursor = Cursors.WaitCursor
        Dim myDataReader As CoreLab.MySql.MySqlDataReader
        mySQLConnection.Open()
        mySQLCommand.CommandText = "Select ID, InvNr, Lieferant, ArtikelNr, " & _
            "Groesse, Farbe, ArtBez, VPreis, DivArt, iCode " & _
            "From ArtikelStamm Where " & _
            "InvNr = '" & txtInvNr.Text & "' and " & _
            "Lieferant = " & txtLieferant.Text & " and " & _
            "ArtikelNr = '" & txtArtNummer.Text & "'"
        mySQLCommand.Connection = mySQLConnection
        myDatareader = mySQLCommand.ExecuteReader
        Me.Cursor = Cursors.Default

        ' OK - Till here, everything works fine

        If myDatareader.Read = True Then

            ' Here should each record be checked

            For i As Integer = 1 To myDataReader.ResultCount

                ' If the Item "DivArt" or the Item "Groesse" & Item "Farbe" are the same as in the textboxes, - the correct Record was found

                If Val(myDataReader.Item("DivArt")) = 1 Then Exit For
                If myDataReader.Item("Groesse") = txtGroesse.Text And _
                    myDataReader.Item("Farbe") = txtFarbe.Text Then
                    Exit For
                End If
                myDataReader.NextResult()
            Next

            'If the end of the Data Reader is reached, that does the record(s) not match - an error should  appear - or when the Data Reader has not reached the end - the data should be displayed.
' But here I am doing soemthing wrong i think, because here I always get false, also when the data exists...

            If myDataReader.Read = False Then
                MsgBox("Kein Artikel gefunden!", MsgBoxStyle.Information, _
                    "Keinen Artikel gefunden...")
                mySQLConnection.Close()
                Exit Sub
            End If
            txtInvNr.Text = myDatareader.Item("InvNr").ToString
            txtLieferant.Text = myDatareader.Item("Lieferant").ToString


Hope you understand my problem....

THX!
Zero-G.
 
Posts: 390
Joined: Sat 09 Dec 2006 12:20

Postby Alexey » Wed 13 Jun 2007 06:45

NextResult method is used to process multiple resultsets, which can be generated by executing batch SQL statements. I don't think this is your intend. You should rather use Read method to iterate through the set of records. For more information please read MySQLDirect .NET documentation.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL