Results 1 to 2 of 2

Thread: create sql statement on text file?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    269

    create sql statement on text file?

    Hi,

    I have a access table, I want to read the record and create a external whatever.SQL file, so I can import to the MySQL server, the file will contain a whole bundle "INSERT statement"

    I know how to get the record set from the access table, but just don't know how to write it to the text file with the correct format.

    The sample record in the text.SQL file should like something below:

    INSERT INTO `table1` VALUES ("","Johnny Knight","ABC Company","Tel: 309-432-3432","USA","50230","343550","106","16","0","0","0","logo.gif","1","0","0","0","","1","","0","","0", "0","1","0");


    Thanks!

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: create sql statement on text file?

    Do you know the table name and field names at design time? If so
    Code:
    'assume the recordset with the Access data is rs
    
    rs.MoveFirst
    Open "File.sql" for Output As #1
    Do
      Print #1, "INSERT INTO "; <table name>; " (<field1 name>, <field2 name>, etc.) VALUES ("; rs.Fields(0).Value; ", "; rs.Fields(1).Value; ", "; etc. ; ");"
      rs.MoveNext
    Until rs.EOF
    Close #1
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width