473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

List and Update code of SQL...

43
Hello everyone good day!

I have this problem in my program.

Situation: I have ListBox that contains all Bottle Number, which is a Primary Key of my Table: Bottles. What I want to do is update all rows in the table Bottles where bottle number = ListAssigned.ListIndex = i. Here is my code: (I've used FOR LOOP to loop in all the entries in my Listbox).

Expand|Select|Wrap|Line Numbers
  1. Private Function UpdateBottles()
  2.  
  3. Dim i As Integer
  4.  
  5. For i = 0 To ListAssigned.ListCount - 1
  6.  
  7.  With rsbot2
  8.  
  9.      .ActiveConnection = cn
  10.      .CursorLocation = adUseClient
  11.      .CursorType = adOpenKeyset
  12.      .LockType = adLockOptimistic
  13.      .Open "SELECT * FROM bottles WHERE bot_number =" & Val(ListAssigned.ListIndex = i)
  14.  
  15.  End With
  16.  
  17.   Call assignBot
  18.  
  19.     With rsbot2
  20.  
  21.         .Update
  22.         .Requery
  23.         .UpdateBatch
  24.  
  25.     End With
  26.  
  27.  rsbot2.Close
  28.  
  29. Next i
  30.  
  31. End Function
  32.  
  33. Private Sub assignBot()
  34.  
  35.  rsbot2(0) = Val(cmboBotNo.Text)
  36.  rsbot2(1) = "Borrowed"
  37.  rsbot2(3) = Val(lblDumOrderId.Caption)
  38.  rsbot2(4) = Val(lblDumID.Caption)
  39.  
  40. End Sub
This code is not working. It didn't update any row in the table. I need help on this.
Thanks and God bless

DaveftL
Nov 10 '07 #1
6 1548
debasisdas
8,127 Expert 4TB
Why you need to Select while you can Update directly .
Nov 11 '07 #2
daveftl
43
Why you need to Select while you can Update directly .
ah okay...over looked that one...thanks
Nov 11 '07 #3
daveftl
43
Why you need to Select while you can Update directly .
ive tried that one but
It is still not working well...it doesnt still update the table...
Nov 12 '07 #4
Killer42
8,435 Expert 8TB
ive tried that one but
It is still not working well...it doesnt still update the table...
Can you show us the latest version?
Nov 13 '07 #5
daveftl
43
Can you show us the latest version?
heres my latest code:
Expand|Select|Wrap|Line Numbers
  1. Private Function UpdateBottles()
  2.  
  3. Dim i As Integer
  4.  
  5. For i = 0 To ListAssigned.ListCount - 1
  6.  
  7.  With rsbot2
  8.  
  9.      .ActiveConnection = cn
  10.      .CursorLocation = adUseClient
  11.      .CursorType = adOpenKeyset
  12.      .LockType = adLockOptimistic
  13.      .Open "UPDATE bottles SET bot_status = ' & Borrowed & ', order_id = '& Val(lblDumOrderId.Caption) & ',cust_id = ' & Val(lblDumID.Caption) & ' WHERE bot_no =" & Val(ListAssigned.ListIndex = i)
  14.       '"UPDATE bottles SET  FROM bottles WHERE bot_number =" & Val(ListAssigned.ListIndex = i)
  15.  
  16.  End With
  17.  
  18.   Call assignBot
  19.  
  20.     With rsbot2
  21.  
  22.         .Update
  23.         .Requery
  24.         .UpdateBatch
  25.  
  26.     End With
  27.  
  28.  'rsbot2.Close
  29.  
  30. Next i
  31.  
  32. End Function
whats wrong with it?

God bless
Nov 14 '07 #6
Killer42
8,435 Expert 8TB
I'm really short on time right now. But I have to say, this whole concept of using Open with the “UPDATE” SQL, then applying an Update method to it, just seems totally bizarre to me. I thought the whole point of the SQL “UPDATE” statement is that you execute it, and it does the update. You don’t use it to retrieve a recordset, then start applying updates to that.

Or am I just out of touch?
Nov 15 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been...
7
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need...
24
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and...
8
by: sudhirlko2001 | last post by:
How to swap two nodes of doubly Linklist
8
by: Vivek | last post by:
Hi, I wish to update the LIST<T> created in PARENT FORM from the CHILD FORM. Currently I have declared the LIST<Role> as public in my parent form. What can I do to update the <LIST>? Thanks
1
by: D Lutheran | last post by:
I need to write some code in some navigation buttons to have the button move up and down list box items. I think I need to start with having the button change an index the buttons are...
1
by: ebernedo | last post by:
Hey guys, I have two main questions First off (pictures are kind of blurry) I have this table http://i197.photobucket.com/albums/aa109/ebernedo/DiscTable.jpg And thats my database I use my...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
1
by: Pauley | last post by:
I have an ASP page that has a list box that allows multiple selections. I can take those items selected and submit them to my SQL table. Of course they are submitted as: selection1, selection2,...
7
by: wizardry | last post by:
i can query the list fine using: select list.list, many_table.list_id_fk from list left join many_table on list.id = many_table.list_id_fk and many_table.userid = 'UserId'; that populates...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.