Do until loop

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 21
Reputation: mpande is an unknown quantity at this point 
Solved Threads: 0
mpande mpande is offline Offline
Newbie Poster

Do until loop

 
0
  #1
Jul 30th, 2009
Good Day People
Please help me, I'm trying to do a do until loop, which can search the database to match the value that is entered in the vb6.0 textbox. but I don't know what to call the value in the database.
It looks something like this.
dim productid as integer
productid=me.productid.text
Do until productid=product_id(this is the value I don't know what to call, it is the value in the database)
PLEASE HELP.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1,130
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 93
cguan_77's Avatar
cguan_77 cguan_77 is offline Offline
Veteran Poster

Re: Do until loop

 
0
  #2
Jul 30th, 2009
hi, this might give you an idea:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. num = 1 ' initialize counter
  2. 'rs is the reference to your recordset change if needed
  3. Do While Not rs.EOF
  4. ' See if the data has been found
  5. If product_id = rs!product_id Then
  6. 'do something here
  7. End If
  8.  
  9. ' If not found move to the next record.
  10. num = num + 1
  11. rs.MoveNext
  12. Loop

and just curious why you need me on this code;
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim productid as integer
  2. productid=me.productid.text
why not do like this:
productid=productid.text

i hope it helps..
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Do until loop

 
0
  #3
Jul 30th, 2009
if it is a specific item you are looking for why search through mulitple records?

  1. sSQL = "Select fields from table where id = " & productid & "
  2.  

then you can run your do while.
Last edited by ProfessorPC; Jul 30th, 2009 at 8:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 912
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 167
vb5prgrmr vb5prgrmr is offline Offline
Posting Shark

Re: Do until loop

 
0
  #4
Jul 31st, 2009
or if it is a partial product id no then...

"Select * from table where productid like '" & sometext & "*'"

if it is text or if not remove the single ticks (')


Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 21
Reputation: mpande is an unknown quantity at this point 
Solved Threads: 0
mpande mpande is offline Offline
Newbie Poster

Re: Do until loop

 
0
  #5
Aug 13th, 2009
Originally Posted by cguan_77 View Post
hi, this might give you an idea:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. num = 1 ' initialize counter
  2. 'rs is the reference to your recordset change if needed
  3. Do While Not rs.EOF
  4. ' See if the data has been found
  5. If product_id = rs!product_id Then
  6. 'do something here
  7. End If
  8.  
  9. ' If not found move to the next record.
  10. num = num + 1
  11. rs.MoveNext
  12. Loop

and just curious why you need me on this code;
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. dim productid as integer
  2. productid=me.productid.text
why not do like this:
productid=productid.text

i hope it helps..
Thanks for your help Cguan
But it still won't work have been at it, trying to find the problem but to no avail, is it not possible to reference a variable in VB6.0 to a variable in oracle database. Because thats all I need.
Do until productid(vb6.0)=productid(database)-this is the problem
if productid(vb6.0)=productid(database) then
do something
loop
end if
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Do until loop

 
0
  #6
Aug 13th, 2009
what are you using to connect to the DB? i am guessing something like this:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim cn As ADODB.Connection
  2. Dim rs As ADODB.Recordset
  3.  
  4. Set cn = New ADODB.Connection
  5. cn.Open 'connection string
  6. Set rs = New ADODB.Recordset
  7. rs.Open "Select fields from table where id = " & productid.text & "", cn
  8. While Not rs.EOF
  9. do something
  10. rs.MoveNext
  11. rs.Close
  12. Set rs = Nothing
  13. cn.Close
  14. Set cn = Nothing
Last edited by ProfessorPC; Aug 13th, 2009 at 10:02 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 21
Reputation: mpande is an unknown quantity at this point 
Solved Threads: 0
mpande mpande is offline Offline
Newbie Poster

Re: Do until loop

 
0
  #7
Aug 14th, 2009
Originally Posted by ProfessorPC View Post
what are you using to connect to the DB? i am guessing something like this:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim cn As ADODB.Connection
  2. Dim rs As ADODB.Recordset
  3.  
  4. Set cn = New ADODB.Connection
  5. cn.Open 'connection string
  6. Set rs = New ADODB.Recordset
  7. rs.Open "Select fields from table where id = " & productid.text & "", cn
  8. While Not rs.EOF
  9. do something
  10. rs.MoveNext
  11. rs.Close
  12. Set rs = Nothing
  13. cn.Close
  14. Set cn = Nothing
Thanks For your help, Proffessor PC.
I think it works, but won't see that properly now because it gives an error later on when I say: if productid=rs!product_id then
rs.open"select fields from table", "update field set data"
but it gives me an error on open(wrong number of arguments or invalid property assignment), could you please help, i have also tried .execute instead of .open, but it gives me the same error message.
Please help!!!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1,130
Reputation: cguan_77 has a little shameless behaviour in the past 
Solved Threads: 93
cguan_77's Avatar
cguan_77 cguan_77 is offline Offline
Veteran Poster

Re: Do until loop

 
0
  #8
Aug 15th, 2009
Originally Posted by mpande View Post
Thanks For your help, Proffessor PC.
I think it works, but won't see that properly now because it gives an error later on when I say: if productid=rs!product_id then
rs.open"select fields from table", "update field set data"
but it gives me an error on open(wrong number of arguments or invalid property assignment), could you please help, i have also tried .execute instead of .open, but it gives me the same error message.
Please help!!!!
hi mpande, the code that Proffessor PC gives you it seems to work fine.. so maybe you can post the code that you try
Last edited by cguan_77; Aug 15th, 2009 at 3:30 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 21
Reputation: mpande is an unknown quantity at this point 
Solved Threads: 0
mpande mpande is offline Offline
Newbie Poster

Re: Do until loop

 
0
  #9
Aug 17th, 2009
Originally Posted by cguan_77 View Post
hi mpande, the code that Proffessor PC gives you it seems to work fine.. so maybe you can post the code that you try
Hi cguan the code that I'm using is this:
If productid = rs!product_id Then
Set updatedb = New ADODB.Connection
updatedb.Open "DSN=waterdb;Password=andile;User ID=eco;Data Source=waterdb"
Set rs1 = New ADODB.Recordset
rs1.Open "Select product_id,qty,stock_date,trans_type,qtydb from stock", "update stock set product_id=productid", "update stock set qty=qty", "update stock set stock_date=date", "update stock set trans_type=trans_type", "update stock set qtydb=qtydb"
With Adodc1
.Recordset.Update
.Recordset.Fields("product_id") = productid
.Recordset.Fields("qty") = qty
.Recordset.Fields("stock_date") = dop
.Recordset.Fields("trans_type") = "trans_type"
.Recordset.Fields("qtydb") = qtydb

End With

Else: MsgBox ("invalid product id")
End If
db.CommitTrans
rs.MoveNext
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Loop

But the problem is at rsi.open, it gives me an error saying-wrong number of arguments or invalid property assignment.
Please help!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Do until loop

 
0
  #10
Aug 17th, 2009
Originally Posted by mpande View Post
Hi cguan the code that I'm using is this:
If productid = rs!product_id Then
Set updatedb = New ADODB.Connection
updatedb.Open "DSN=waterdb;Password=andile;User ID=eco;Data Source=waterdb"
Set rs1 = New ADODB.Recordset
rs1.Open "Select product_id,qty,stock_date,trans_type,qtydb from stock", "update stock set product_id=productid", "update stock set qty=qty", "update stock set stock_date=date", "update stock set trans_type=trans_type", "update stock set qtydb=qtydb"
With Adodc1
.Recordset.Update
.Recordset.Fields("product_id") = productid
.Recordset.Fields("qty") = qty
.Recordset.Fields("stock_date") = dop
.Recordset.Fields("trans_type") = "trans_type"
.Recordset.Fields("qtydb") = qtydb

End With

Else: MsgBox ("invalid product id")
End If
db.CommitTrans
rs.MoveNext
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Loop

But the problem is at rsi.open, it gives me an error saying-wrong number of arguments or invalid property assignment.
Please help!!
okay lets see what we can do lol. so you get the data from the product id. you are updating the table with the values in txt boxes? if that is the way your are working it lets try this.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. rs1.Open "UPDATE Stock (qty, stock_date, trans_type, qtydb ) Values (" & qtyfield &", " & stock_datefield &", " & trans_type &", " & qtydbfield &")", updatedb

been a long day hope that works lol
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 1770 | Replies: 27
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC