datareader - move to next record

kAnne

Active member
Joined
Jan 17, 2006
Messages
26
Programming Experience
1-3
Hello again everyone,

I have a simple question, Well, it seems simple but I cant get it to work!

I have successfully got the connection to the database etc and its all fine, but I cant get the app to move to the next record from a button click.

Im guessing its something to do with the reader.nextresult method?

While im here.......Ita quiz im making. And I was wondering how I would go about keeping a users score? I was thinking an array, but reading around, it seems im not right?

Thanks guys :)
 
you shouldn't be using the Reader for that.... the reader is designed to be a high-speed readonly data access when you need to populate a combo or a list or something like that.

It shouldn't be used to wait for user interaction. For that you should be loading everything into a dataset, then looping through that.

But, in short, to move to the next record in a reader, use the .Read method.

-tg
 
Right, well, I guess im in trouble then! Ive only just mastered getting data from the DB using a reader. Now I have to use a dataset?

Ive looked around, and cant really find anything useful to teach me datasets and datatables. Any links etc would be very much appreciated!!

Are you using MSAccess as backend ???
However attach the project ( i need the DB design and GUI) and i'll show you couple tips including how to fetch next question(s).


Not really keen on posting my app, seems wrong!!
 
Check my sig... there;s a couple of ADO.NET tutorials..

-tg
 
I'd say it depends.... if the Reader is only bringing back one record at a time, then perhapse not.... but if the reader is bringing back multiple records and simply disaplays one at a time, only exectuing the .Read when the user clicks the next button, then (and this is just MY opinion) that's not so good. Readers lock their connections, so you can't use that connection again until the reader closes. If this is the case, then a datatable or dataset would be more appropriate and efficient.

-tg
 
Hey wait a minute ... 1st let me see your app in this stage as well as DB. Btw, why you ignored my reply? DataReader is still in game. Don't change the approach maybe you dont have to do that.
I am waiting for your feedback
I wouldnt dream of ignoring you!! Have a look at my last post...

there isnt much data being pulled from the DB (access btw), so im thinking data set will suffice. Ive got it working so far, but still cant move to next record.

It gets confusing (well..for me anyway!) because I have two forms...One holds the main .swf file which is launched first. When the user selects to learn a specific subject, a button is present which allows them to click on it to take a quiz. This button sends an fscommand to VB to open up form2 (the quiz form) and pull the questions from the DB to that particular subject.

I have all the code in form1 so far as this is where the main .swf is held. and the button for the 'next question' is an fscommand from flash (if the user clicks on next question..tell VB its been selected and move to next question)

there are 3 different subjects in total and 4 subcategories for each subject. So the SQL depends on the subject that is being learnt, and the sub category within that subject.

Does this make any sense at all?!

heres my code so far........

VB.NET:
Private Const con As String = ("Provider=Microsoft.Jet.OleDB.4.0;Data Source= C:\db.mdb;")
    Dim subject As String
    Dim tablename As String
    Dim dlgRes As DialogResult
    Dim ds As New System.Data.DataSet()
    Dim F2 As New form2()
    Dim inc As Integer
    Dim maxrows As Integer

Public Sub Flash1_FSCommand(ByVal sender As Object, ByVal e As AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent) Handles Flash1.FSCommand
        Select Case e.command

            Case "quiz_title"
                F2.Text = e.args

            Case "exit"
                MessageBox.Show(e.args, "EClassroom", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
                Select Case dlgRes
                    Case dlgRes = DialogResult.Yes
                        Application.Exit()
                    Case DialogResult.Cancel
                        Exit Sub
                    Case DialogResult.No
                        Exit Sub
                End Select
        End Select

        If e.command = "Romans" Then
            Try
                subject = e.args
                tablename = "Romans"
                Dim DBConnection As New OleDb.OleDbConnection(con)
                Dim SelectQuestions As New OleDb.OleDbCommand("SELECT * from " & tablename & " WHERE subject = '" & subject & "'", DBConnection)
                Dim NWAdaptor As New OleDb.OleDbDataAdapter(SelectQuestions)
                NWAdaptor.SelectCommand.Connection = DBConnection
                NWAdaptor.Fill(ds, "Questions")

                maxrows = ds.Tables("Questions").Rows.Count
                    If inc <> maxrows - 1 Then
                        inc = inc + 1
                        Navigate()
                    Else
                        MsgBox("No More Rows")
                    End If
                F2.ShowDialog()
            Catch ex As System.Exception '
                MessageBox.Show(ex.Message)
            End Try
End If
 End Sub

    Private Sub Navigate()
        F2.question.Text = ds.Tables("Questions").Rows(inc).Item(2)
        F2.answer1.Text = ds.Tables("Questions").Rows(inc).Item(3)
        F2.answer2.Text = ds.Tables("Questions").Rows(inc).Item(4)
        F2.answer3.Text = ds.Tables("Questions").Rows(inc).Item(5)
    End Sub
 
Last edited:
kulrom said:
say it is the case and you need to fetch 1MB data ... are you sure it is again good idea?
OK, I'll admit... 1MB is a bit of data.... and if at all possible I would try to limit the amount of data being returned. If we;re talking about a single record of 1MB, then I'm not convinced a Reader is still any better. And if we are talking about that kind of size, odds are the back end is a bit more powerfull than Access and hopefully would have stored procedure capabilities (at which point I would return what I can through output parameters.)

Generaly I try my best to limit the amount of data being returned. But sometimes it can't be helped either.

And it would also depend on what I plan to do with that 1MB of data...

Problem with this kind of stuff, there's no magic bullet and it has to be taken on a case by case process.

-tg
 
Back
Top