Bulk Sql sentecences execute from Vb6 project

Posted on 2005-04-11
Last Modified: 2010-04-17
Hello Experts
I would like to know how can I process and text file with undreds of lines containing SQL Sentences
Do I have to go line by line assigning each line to a string variable and executing it? or is there any other way to launch it all together
Question by:diegohugo
    LVL 6

    Expert Comment


    There might be a way to create a Stored Procedure using the commands from the text file but you're still going to have to iterate through the file to extract each command so it might be just as easy to just go through executing each line at a time.

    LVL 14

    Accepted Solution

    hi try this

    'Add references
    'Project Menu -> References ->
    '            Microsoft Scripting Runtime
    '            Microsoft ActiveX Data Objects Library 2.5
    '                                             (or higher)
    Private Sub Command1_Click()
    Dim objCon As New ADODB.Connection
    Dim objFso As New FileSystemObject
    Dim objTextStream As TextStream
    Dim sQuery As String
        objCon.CursorLocation = adUseClient
        objCon.ConnectionString = "Place_Your_Database_connection_String_here"
        objCon.Open , "user_name", "password"
        Set objTextStream = objFso.OpenTextFile("C:\Your_Sql_statments.txt", ForReading)
        While Not objTextStream.AtEndOfStream
            sQuery = objTextStream.ReadLine
            If Trim(sQuery) <> "" Then objCon.Execute sQuery
        Set objFso = Nothing
        Set objCon = Nothing
    End Sub


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now