944,096 Members | Top Members by Rank

Ad:
Dec 13th, 2005
0

how VB get data from database randomly

Expand Post »
hi guy,

i need this ugently.. hope someone can help me out..

i need to get data from database,
but want it to take randomly and also dont want to get data duplicate.



Ex; i get data A from DB, then there will be a next button. i wan to go next data after i click it,
and get data c, later i dont wan to get back A & C again.

i`m doing Question and Answer thing.

thanks alot..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bang2711 is offline Offline
24 posts
since Aug 2005
Dec 13th, 2005
0

Re: how VB get data from database randomly

this is my program..
please help me
Attached Files
File Type: zip testing.zip (419.2 KB, 702 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bang2711 is offline Offline
24 posts
since Aug 2005
Dec 14th, 2005
0

Re: how VB get data from database randomly

Hi Bang2711,

First of all you are missing two .dlls in your .zip file:
XVoice.dll
ExButton.dll

Next, I see you have references to both DAO and ADODB in your project, unless you actually use both (and from what I see you are only using DAO) remove the one you are not using to avoid conflicts, OR specify which type you are using,
i.e. Dim rstdb1 As DAO.Recordset OR
Dim rstdb1 As ADODB.Recordset
Otherwise VB will pick which ever one it wants to...

Now to a possible soution.

An idea come to my mind as soon as I read your post and here it is.

Create a user defined type and a public variable of that type:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Type DBWords
  2. DataID As Long
  3. Used As Boolean
  4. End Type
  5.  
  6. Public DBWordsArr() As DBWords

You do NOT want to set a limit here since you want to be able to resize it dynamically depending on the data in your DB.

Next you load your array with the IDs from your table PicSentenses and FALSE in the boolean part.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Set rstdb1 = db.OpenRecordset("SELECT ID FROM PicSentenses")
  2. rstdb1.MoveLast 'Will get an accurate RecordCount
  3. rstdb1.MoveFirst
  4. ReDim DBWordsArr(rstdb1.RecordCount -1)
  5. i = 0
  6. 'Unless you want to use a 1-based array
  7. 'ReDim DBWordsArr(1 to rstdb1.RecordCount)
  8. 'i = 1
  9. While Not rstdb1.EOF
  10. DBWordsArr(i).DataID = rstdb1!ID
  11. DBWordsArr(i).Used = False
  12. rstdb1.MoveNext
  13. i = i + 1
  14. Wend
  15. 'ALWAYS close your recordsets in VB otherwise you are prone to memory leaks, yes EVEN in VB... :)
  16. rstdb1.Close
  17. Set rstdb1 = Nothing

Then you use your random code to get the next array element to use verifying for Used, I would create a function that returns a new random number within the range of subscripts of DBWordsArr
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. i = GetNextElement()
  2. While DBWordsArr(i).Used
  3. i = GetNextElement()
  4. Wend
  5. Set rstdb2=db.OpenRecordset("SELECT * FROM PicSentenses WHERE ID = " & DBWordsArr(i).DataID)

To guard against a infinite loop I would also keep counters of how many items I have in the array and of how many I have used so far.

Whenever you visit on node of your array you set the Used flag to TRUE and then you cannot get that item back until you have gone through the entire array and reset all the Used flags to FALSE.

Hope this makes sense and that it helps

Have fun

Yomet

P.S. I have not tested this code as I just typed it here in the answer window...
Reputation Points: 16
Solved Threads: 10
Junior Poster
Yomet is offline Offline
134 posts
since Nov 2005
Dec 14th, 2005
0

Re: how VB get data from database randomly

hi Yomet,

thanks alot for ur help
i have solve the problem..

have a great day..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bang2711 is offline Offline
24 posts
since Aug 2005
Oct 14th, 2010
0
Re: how VB get data from database randomly
I need the exact code to connect to oracle8i from vb 6.0.
Please send the code if you have

Thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ganesh_m is offline Offline
1 posts
since Oct 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Hiding a form with keyboard shortcuts...
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: NEED HELP on EXCELVB LISTBOX DATA TRANSFER TO EXCEL RANGES





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC