• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Bulk Sql sentecences execute from Vb6 project

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
thanks
0
diegohugo
Asked:
diegohugo
1 Solution
 
TDSnetCommented:
Hi,

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.

Cheers,
Jack
0
 
Shiju SasidharanAssoc Project ManagerCommented:
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
    Wend
    objTextStream.Close
    Set objFso = Nothing
    Set objCon = Nothing
End Sub
'===============================

;-)
Shiju
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now