Results 1 to 5 of 5

Thread: create sql database from txt file via visual basic (6.0)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,943

    create sql database from txt file via visual basic (6.0)

    Admit have a txt file similar:

    filed1 filed2
    aaaaaaaaaa bbbbbbbbbbbbbb
    cccccccccccc dddddddddddddd
    .............
    yyyyyyyyyy zzzzzzzzzzzzzz

    How to create VIA VISUAL BASIC (ADO or DAO) a new SQL Server databse?
    ... in effect i want to create a database and table with 2 fileds and import data from txt file "ex novo"...

    found thsi but vb.net and ado.net:

    http://support.microsoft.com/kb/305079

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: create sql database from txt file via visual basic (6.0)

    The method is very similar... the SQL string is the same (tho I presume you want different fields etc, so see the SQL tutorials in our Database FAQs), you just need to connect to the database (and execute the query) using the usual syntax.

    Using ADO, that could be:
    Code:
        Dim myConn As ADODB.Connection 
        Set myConn = New ADODB.Connection 
    
        myConn.Open "Driver={SQL Server};Server=(local)\netsdk;" & _
                                                        "uid=sa;pwd=;database=master"
    
        str = "CREATE DATABASE ... "
    
        myConn.Execute str
    
        myConn.Close
        set myConn = Nothing
    Note that this is not a ideal example - you should add error handling etc.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: create sql database from txt file via visual basic (6.0)

    And, even though the code is for .NET, you can use the CREATE DATABASE query from that example as a starting point for setting yours up.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,943

    Re: create sql database from txt file via visual basic (6.0)

    Quote Originally Posted by si_the_geek
    The method is very similar... the SQL string is the same (tho I presume you want different fields etc, so see the SQL tutorials in our Database FAQs), you just need to connect to the database (and execute the query) using the usual syntax.

    Using ADO, that could be:
    Code:
        Dim myConn As ADODB.Connection 
        Set myConn = New ADODB.Connection 
    
        myConn.Open "Driver={SQL Server};Server=(local)\netsdk;" & _
                                                        "uid=sa;pwd=;database=master"
    
        str = "CREATE DATABASE ... "
    
        myConn.Execute str
    
        myConn.Close
        set myConn = Nothing
    Note that this is not a ideal example - you should add error handling etc.
    hI all
    Tks for sugestion.
    My friend suggest me to use SQL DMO object in VB to create database and table, wath you think?
    In other case admit i have created a db and table how to insert value from txt into the new sql database?


    ...

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: create sql database from txt file via visual basic (6.0)

    SQL DMO is certainly a valid option - but I'm afraid I can't help you with that, as I don't use it myself (so the code works for other DBMS's, I've only ever used Create statements, or occasionally ADOX).

    To add data once the table have been created, use the usual methods - if you are using ADO, there are examples in this FAQ article.

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