[RESOLVED] fill a database with numbers
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] fill a database with numbers

  1. #1
    Join Date
    Mar 2013
    Posts
    4

    [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.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: fill a database with numbers

    Write the code into a text file (with comma or delimiters) and then IMPORT it
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2005
    Posts
    1,074

    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 ...

  4. #4
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    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.

  5. #5
    Join Date
    Mar 2013
    Posts
    4

    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.

  6. #6
    Join Date
    Mar 2013
    Posts
    4

    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.

    Quote Originally Posted by jggtz View Post
    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)

  7. #7
    Join Date
    Mar 2013
    Posts
    4

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center