-
March 17th, 2013, 02:59 PM
#1
[RESOLVED] fill a database with numbers
Hi fellow programmers. I am trying to do what I thought was a very simple task in VB6 and Access and am pulling my hair out.
What I want to to is fill an Access table with four fields labeled Num1 through Num4 with all sets of four numbers from one to one hundred. For exampleL 1-2-3-4; 1-2-3-5; 1-2-3-6 etc.
I have the for - next loops easily enough . The four text boxes are bound to the number table in the database. My problem is I cannot insert each set of four numbers into the database. Any help is appreciated.
Here is my code for generating the numbers...
For a = 1 to 97
For b = a + 1 to 98
For c = b + 1 to 99
For d = c + 1 to 100
' Here is where I want to put the numbers into the Access database table.
'I am using the ADO data control and have a reference to ADO 2.0 in the progect.
numbs.recordset.addnew
numbs.recordset.update
Next d
Next c
Next b
Next a
I've tried different things and just get errors and can't figure out what I am doing wrong. Please hep. Thanks.
-
March 17th, 2013, 05:28 PM
#2
Re: fill a database with numbers
Write the code into a text file (with comma or delimiters) and then IMPORT it
-
March 17th, 2013, 09:48 PM
#3
Re: fill a database with numbers
I never used Data Control but try next
Code:
For a = 1 to 97
For b = a + 1 to 98
For c = b + 1 to 99
For d = c + 1 to 100
numbs.recordset.addnew
numbs.recordset!Num1 = a
numbs.recordset!Num2 = b
numbs.recordset!Num3 = c
numbs.recordset!Num4 = d
numbs.recordset.update
Next d
Next c
Next b
Next a
Another is to display the numbers in 4 text boxes that are linked (bound controls) with the table fields (yes those fields that David say are evil and I agree)
Last edited by jggtz; March 17th, 2013 at 09:53 PM.
Reason: syntax
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
March 18th, 2013, 01:53 AM
#4
Re: fill a database with numbers
ADO 2.0? That is way way out of date. I also do not use the data control and would not recommend using it and especially not with bound controls.
For your task i would suggest creating and executing a SQL Insert statement.
While the code above will work and should not be an issue on a single user system, you can run into issues in a multi-user environment. Insert statements are typically faster and safer.
Always use [code][/code] tags when posting code.
-
March 18th, 2013, 01:55 PM
#5
Re: fill a database with numbers
Thanks David. I appreciate the advice, however, I want to be able to talk to the database from withing the application.
I have resolved the problem using JG's suggestion and getting rid of the data control. It's all being done with code now and it works great.
-
March 18th, 2013, 01:59 PM
#6
Re: fill a database with numbers
Thanks JG. I solved the problem using your suggestion. I got rid of the data control and accomplished the task in code.
Thanks again for taking the time to respond to my question.
Originally Posted by jggtz
I never used Data Control but try next
Code:
For a = 1 to 97
For b = a + 1 to 98
For c = b + 1 to 99
For d = c + 1 to 100
numbs.recordset.addnew
numbs.recordset!Num1 = a
numbs.recordset!Num2 = b
numbs.recordset!Num3 = c
numbs.recordset!Num4 = d
numbs.recordset.update
Next d
Next c
Next b
Next a
Another is to display the numbers in 4 text boxes that are linked (bound controls) with the table fields (yes those fields that David say are evil and I agree)
-
March 18th, 2013, 02:03 PM
#7
Re: fill a database with numbers
Thanks for the advice. My problem is now resolved. I know ADO 2.0 is old. I am using VB 6.0 on a laptop with Win98. The project is a small one for a friend and will not grow into a large scale application. Only single user so this one is fine with what I am using. It's on the laptop for portability. That way I can take it and work on it wherever I am. One day I'll upgrade to a better laptop but it's not a requirement at this time. Thanks again for taking the time to respond to my question.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|