OleDbSelect Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Perry Langla

    #1

    OleDbSelect Help

    I can not seem to figure this out, please help. This program worked
    perfectly in Visual Studio 2003. The program gets the information from an
    Access Database. I am using OleDbSelectComm and to select certain records.
    When I run the program and click Button1 the test works OK. The problem is
    when I select another Button the correct records appear but the
    QuestionCounter is not correct. It shows " Question 10 of 10 ". I think it
    has something to do with the Count not releasing.



    Here is a sample.



    'This is for counting questions

    Private Sub QuestionCounter ()

    Dim Question, Current As Integer

    Question = Me.BindingConte xt(DataSet1, "Table1").C ount

    Current = Me.BindingConte xt(DataSet1, "Table1").Posit ion + 1

    Label1.Text = "Question " & Current.ToStrin g & " of " &
    Question.ToStri ng

    End Sub



    'This Button for Test 1

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click

    Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
    WHERE (ID Between 1 And 10)"

    OleDbDataAdapte r1.Fill(DataSet 1)

    QuestionCounter ()

    End Sub



    'This Button for Test 2

    Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button2.Click

    Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
    WHERE (ID Between 11 And 20)"

    OleDbDataAdapte r1.Fill(DataSet 1)

    QuestionCounter ()

    End Sub



    'This Button for Test 2

    Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button3.Click

    Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
    WHERE (ID Between 21 And 30)"

    OleDbDataAdapte r1.Fill(DataSet 1)

    QuestionCounter ()

    End Sub





    Any help would be appreciated.

    Thanks Perry Langla plangla@hotmail .com



  • Cor Ligthert[MVP]

    #2
    Re: OleDbSelect Help

    Perry,

    Can you try it changing your code to this.
    OleDbDataAdapte r1.Fill(Dataset 1,"Table1")

    I get the idea that it is possible that you are filling three or more tables
    at the moment.
    (The select name in your select string is not the name in your dataset,
    Table1, Table2 etc are default ones)

    Cor


    "Perry Langla" <plangla@hotmai l.comschreef in bericht
    news:D32A2092-7891-403D-9557-67C5E059D02D@mi crosoft.com...
    >I can not seem to figure this out, please help. This program worked
    >perfectly in Visual Studio 2003. The program gets the information from an
    >Access Database. I am using OleDbSelectComm and to select certain records.
    >When I run the program and click Button1 the test works OK. The problem is
    >when I select another Button the correct records appear but the
    >QuestionCounte r is not correct. It shows " Question 10 of 10 ". I think it
    >has something to do with the Count not releasing.
    >
    >
    >
    Here is a sample.
    >
    >
    >
    'This is for counting questions
    >
    Private Sub QuestionCounter ()
    >
    Dim Question, Current As Integer
    >
    Question = Me.BindingConte xt(DataSet1, "Table1").C ount
    >
    Current = Me.BindingConte xt(DataSet1, "Table1").Posit ion + 1
    >
    Label1.Text = "Question " & Current.ToStrin g & " of " &
    Question.ToStri ng
    >
    End Sub
    >
    >
    >
    'This Button for Test 1
    >
    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    >
    Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
    WHERE (ID Between 1 And 10)"
    >
    OleDbDataAdapte r1.Fill(DataSet 1)
    >
    QuestionCounter ()
    >
    End Sub
    >
    >
    >
    'This Button for Test 2
    >
    Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button2.Click
    >
    Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
    WHERE (ID Between 11 And 20)"
    >
    OleDbDataAdapte r1.Fill(DataSet 1)
    >
    QuestionCounter ()
    >
    End Sub
    >
    >
    >
    'This Button for Test 2
    >
    Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button3.Click
    >
    Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
    WHERE (ID Between 21 And 30)"
    >
    OleDbDataAdapte r1.Fill(DataSet 1)
    >
    QuestionCounter ()
    >
    End Sub
    >
    >
    >
    >
    >
    Any help would be appreciated.
    >
    Thanks Perry Langla plangla@hotmail .com
    >
    >
    >

    Comment

    • Perry Langla

      #3
      Re: OleDbSelect Help

      Hi Cor,
      This suggestion worked the same.
      I am not having a problem with the OleDbDataAdapte r1.Fill.
      The program I am coding is for a Test Generator. The program has various
      buttons that select individual test. ( over 100 separate test)
      The database has 2400 records


      Example (have several button like this)


      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button1.Click
      Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
      WHERE (ID Between 1 And 10)"
      OleDbDataAdapte r1.Fill(DataSet 1, "Table1")
      QuestionCounter ()
      End Sub

      When I run the program it works fine for the first test. I then run another
      test the questions and answers load correctly but the question counter is
      stuck on "Question 10 of 10", from the last test taken.

      Here is an example of the question counter (This works correct for first
      test)

      Private Sub QuestionCounter ()
      Dim Question, Current As Integer
      Question = Me.BindingConte xt(DataSet1, "Table1").C ount
      Current = Me.BindingConte xt(DataSet1, "Table1").Posit ion + 1
      Label1.Text = "Question " & Current.ToStrin g & " of " &
      Question.ToStri ng
      End Sub


      Here is an example of the question advance. (Also works correctly for first
      test)

      Private Sub NextQuestion()
      Dim Question, Current As Integer
      Question = Me.BindingConte xt(DsTest11, "Table1").C ount
      Current = Me.BindingConte xt(DsTest11, "Table1").Posit ion + 1

      If Current.ToStrin g = Question.ToStri ng Then
      CloseTest()
      Else
      Me.BindingConte xt(DsTest11, "Table1").Posit ion += 1
      QuestionCounter ()
      End If
      End Sub

      I not sure if it has something to do with initiating another
      "OleDbSelectCom mand" .
      I think it selects correctly for the second Test because the first question
      is correct but Question Counter is not. Is there a way to reset the Count
      and Position of
      the records selected?

      Thanks Perry Langla


      "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
      news:AE48F29F-0555-4D63-95DA-AE484CD5E5E2@mi crosoft.com...
      Perry,
      >
      Can you try it changing your code to this.
      OleDbDataAdapte r1.Fill(Dataset 1,"Table1")
      >
      I get the idea that it is possible that you are filling three or more
      tables at the moment.
      (The select name in your select string is not the name in your dataset,
      Table1, Table2 etc are default ones)
      >
      Cor
      >
      >
      "Perry Langla" <plangla@hotmai l.comschreef in bericht
      news:D32A2092-7891-403D-9557-67C5E059D02D@mi crosoft.com...
      >>I can not seem to figure this out, please help. This program worked
      >>perfectly in Visual Studio 2003. The program gets the information from an
      >>Access Database. I am using OleDbSelectComm and to select certain records.
      >>When I run the program and click Button1 the test works OK. The problem is
      >>when I select another Button the correct records appear but the
      >>QuestionCount er is not correct. It shows " Question 10 of 10 ". I think
      >>it has something to do with the Count not releasing.
      >>
      >>
      >>
      >Here is a sample.
      >>
      >>
      >>
      >'This is for counting questions
      >>
      >Private Sub QuestionCounter ()
      >>
      > Dim Question, Current As Integer
      >>
      > Question = Me.BindingConte xt(DataSet1, "Table1").C ount
      >>
      > Current = Me.BindingConte xt(DataSet1, "Table1").Posit ion + 1
      >>
      > Label1.Text = "Question " & Current.ToStrin g & " of " &
      >Question.ToStr ing
      >>
      >End Sub
      >>
      >>
      >>
      >'This Button for Test 1
      >>
      >Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      >System.EventAr gs) Handles Button1.Click
      >>
      > Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
      >WHERE (ID Between 1 And 10)"
      >>
      > OleDbDataAdapte r1.Fill(DataSet 1)
      >>
      > QuestionCounter ()
      >>
      > End Sub
      >>
      >>
      >>
      >'This Button for Test 2
      >>
      >Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
      >System.EventAr gs) Handles Button2.Click
      >>
      > Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
      >WHERE (ID Between 11 And 20)"
      >>
      > OleDbDataAdapte r1.Fill(DataSet 1)
      >>
      > QuestionCounter ()
      >>
      >End Sub
      >>
      >>
      >>
      >'This Button for Test 2
      >>
      >Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
      >System.EventAr gs) Handles Button3.Click
      >>
      > Me.OleDbSelectC ommand1.Command Text = "SELECT Table1.* FROM Table1
      >WHERE (ID Between 21 And 30)"
      >>
      > OleDbDataAdapte r1.Fill(DataSet 1)
      >>
      > QuestionCounter ()
      >>
      >End Sub
      >>
      >>
      >>
      >>
      >>
      >Any help would be appreciated.
      >>
      >Thanks Perry Langla plangla@hotmail .com
      >>
      >>
      >>
      >

      Comment

      • Cor Ligthert[MVP]

        #4
        Re: OleDbSelect Help

        Peter,

        I did not say that you have problems with the fill.

        The fill is consequently filling a table, however I am not sure that you are
        filling the same table. I have the idea that you are filling everytime
        another table. You know that a dataset is just a wrapper around tables.
        Renaming the dataset is not what I asked.

        This can be the situation in your dataset after the fills

        Dataset1.
        Table1
        Table2
        Table3
        Table100

        The result of your queuries around Table1. will then all the time be the
        same. Why don't you eliminate the dataset stuff and just look what happens
        with the single table, in your code I see you only using one table,
        therefore as far as I can see there is no need for a wrapper.

        Cor

        Comment

        Working...