OleDbSelect Help

P

Perry Langla

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 OleDbSelectCommand 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.BindingContext(DataSet1, "Table1").Count

Current = Me.BindingContext(DataSet1, "Table1").Position + 1

Label1.Text = "Question " & Current.ToString & " of " &
Question.ToString

End Sub



'This Button for Test 1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.OleDbSelectCommand1.CommandText = "SELECT Table1.* FROM Table1
WHERE (ID Between 1 And 10)"

OleDbDataAdapter1.Fill(DataSet1)

QuestionCounter()

End Sub



'This Button for Test 2

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Me.OleDbSelectCommand1.CommandText = "SELECT Table1.* FROM Table1
WHERE (ID Between 11 And 20)"

OleDbDataAdapter1.Fill(DataSet1)

QuestionCounter()

End Sub



'This Button for Test 2

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

Me.OleDbSelectCommand1.CommandText = "SELECT Table1.* FROM Table1
WHERE (ID Between 21 And 30)"

OleDbDataAdapter1.Fill(DataSet1)

QuestionCounter()

End Sub





Any help would be appreciated.

Thanks Perry Langla (e-mail address removed)
 
C

Cor Ligthert[MVP]

Perry,

Can you try it changing your code to this.
OleDbDataAdapter1.Fill(Dataset1,"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
 
P

Perry Langla

Hi Cor,
This suggestion worked the same.
I am not having a problem with the OleDbDataAdapter1.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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.OleDbSelectCommand1.CommandText = "SELECT Table1.* FROM Table1
WHERE (ID Between 1 And 10)"
OleDbDataAdapter1.Fill(DataSet1, "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.BindingContext(DataSet1, "Table1").Count
Current = Me.BindingContext(DataSet1, "Table1").Position + 1
Label1.Text = "Question " & Current.ToString & " of " &
Question.ToString
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.BindingContext(DsTest11, "Table1").Count
Current = Me.BindingContext(DsTest11, "Table1").Position + 1

If Current.ToString = Question.ToString Then
CloseTest()
Else
Me.BindingContext(DsTest11, "Table1").Position += 1
QuestionCounter()
End If
End Sub

I not sure if it has something to do with initiating another
"OleDbSelectCommand" .
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
 
C

Cor Ligthert[MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top