473,395 Members | 1,972 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,395 software developers and data experts.

How to Update Every Record in a Table

Mel
Can anyone assist me in how I would structure this code to update
every record in a table? I need to loop through each record and
increase the cost field by a certain percentage. How do I loop
through *and* update each record? Here is my code so far:

'Start of Example Code
Dim strConStand As String = "Provider=Microsoft.JET.OLEDB.4.0;Data
Source =c:\w\standards.mdb"
Dim strFreight As String = "Select [Cost] FROM [Freight];"
Dim recFreight As System.Data.OleDb.OleDbDataReader
Dim conFreight As New
System.Data.OleDb.OleDbConnection(strConStand)
Dim comFreight As New System.Data.OleDb.OleDbCommand(strFreight,
conFreight)

conFreight.Open()
recFreight = comFreight.ExecuteReader

Do While recFreight.Read
'increase every cost by 5%
Loop
recFreight.Close()
conFreight.Close()
'End of Example Code
Aug 18 '08 #1
2 1400

That's the last thing you want to do is LOOP and UPDATE.

Here is a one hit (bulk update) statement.

Update [Freight] Set [Cost] = ([Cost] * 1.05)

Use .ExecuteNonQuery

"Mel" <ML********@gmail.comwrote in message
news:d7**********************************@26g2000h sk.googlegroups.com...
Can anyone assist me in how I would structure this code to update
every record in a table? I need to loop through each record and
increase the cost field by a certain percentage. How do I loop
through *and* update each record? Here is my code so far:

'Start of Example Code
Dim strConStand As String = "Provider=Microsoft.JET.OLEDB.4.0;Data
Source =c:\w\standards.mdb"
Dim strFreight As String = "Select [Cost] FROM [Freight];"
Dim recFreight As System.Data.OleDb.OleDbDataReader
Dim conFreight As New
System.Data.OleDb.OleDbConnection(strConStand)
Dim comFreight As New System.Data.OleDb.OleDbCommand(strFreight,
conFreight)

conFreight.Open()
recFreight = comFreight.ExecuteReader

Do While recFreight.Read
'increase every cost by 5%
Loop
recFreight.Close()
conFreight.Close()
'End of Example Code

Aug 18 '08 #2
Mel
On Aug 18, 10:46 am, "sloan" <sl...@ipass.netwrote:
That's the last thing you want to do is LOOP and UPDATE.

Here is a one hit (bulk update) statement.

Update [Freight] Set [Cost] = ([Cost] * 1.05)

Use .ExecuteNonQuery

"Mel" <MLights...@gmail.comwrote in message

news:d7**********************************@26g2000h sk.googlegroups.com...
Can anyone assist me in how I would structure this code to update
every record in a table? I need to loop through each record and
increase the cost field by a certain percentage. How do I loop
through *and* update each record? Here is my code so far:
'Start of Example Code
Dim strConStand As String = "Provider=Microsoft.JET.OLEDB.4.0;Data
Source =c:\w\standards.mdb"
Dim strFreight As String = "Select [Cost] FROM [Freight];"
Dim recFreight As System.Data.OleDb.OleDbDataReader
Dim conFreight As New
System.Data.OleDb.OleDbConnection(strConStand)
Dim comFreight As New System.Data.OleDb.OleDbCommand(strFreight,
conFreight)
conFreight.Open()
recFreight = comFreight.ExecuteReader
Do While recFreight.Read
'increase every cost by 5%
Loop
recFreight.Close()
conFreight.Close()
'End of Example Code
Ahh, it's all coming back to me now. Thanks for the guidance to shake
my cobwebs loose; it worked great.
Aug 18 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Pastrovick | last post by:
I use a function, myrandomPIN (), to generate random PIN numbers. The following sql query updates records with the SAME PIN number but. I want to generate DIFFERENT pin numbers for every record....
6
by: Rey | last post by:
How can I update every record of a given table one by one. I need to update a field (date) with a different, random date for each record. loop { generate random date; update one record with...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
22
by: pbd22 | last post by:
hi. I am having probelms with an update statement. every time i run it, "every" row updates, not just the one(s) intended. so, here is what i have. i have tried this with both AND and OR and...
1
by: jmarcrum | last post by:
Hey everyone, I have a question that's been troubling me for a bit. I work for Alabama Power. I have 1 table (tblOutages). Every morning I import a list of Power Outages for the state of...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
2
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.