0% found this document useful (0 votes)
10 views2 pages

ITELEC2 CSEL2 SQL File Importing Mod 4

Lessons for information technology students

Uploaded by

Zyra Mabunga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

ITELEC2 CSEL2 SQL File Importing Mod 4

Lessons for information technology students

Uploaded by

Zyra Mabunga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Golden West Colleges

College of Information Technology Education


Alaminos City, Pangasinan

Data Warehousing
Module 4

Prepared by:
Kairos Jil I. Molina
[email protected]
CSEL2 / ITELEC2 – Data Warehousing

*SQL File Importing on Run-time


1. Add an “OpenFileDialog” from the toolbox, name it “ofdLoadSqlFile”
3. Add the code below for the Click event of Load SQL File.

Dim sqlLocation As String


Dim sqlFilename As String
Try
With ofdLoadSqlFile
.FileName = ""
'the title of the window to open a file
.Title = "Import SQL file..."
'the extension filter
.Filter = "SQL Files|*.sql"
''now to open the dialogue and check if OK has been pressed
If .ShowDialog = Windows.Forms.DialogResult.OK Then
sqlFilename = System.IO.Path.GetFileName(ofdLoadSqlFile.FileName)
Dim result As Integer = MessageBox.Show("Are you sure you want to
import " & sqlFilename & "?", "Confirmation", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question)
If result = DialogResult.Cancel Then
'Do nothing
ElseIf result = DialogResult.No Then
'Do noting
ElseIf result = DialogResult.Yes Then
Try
sqlLocation =
System.IO.Path.GetFullPath(ofdLoadSqlFile.FileName)
Dim content As String =
System.IO.File.ReadAllText(sqlLocation)
Dim sqlScript As New MySqlScript(con)
sqlScript.Query = content ' query string
sqlScript.Execute()
' other stuff
MessageBox.Show("SQL file successfully imported.",
"Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

End If
Else
MessageBox.Show("Select an SQL file to proceed.", "Information",
MessageBoxButtons.OK, MessageBoxIcon.Information)
'put the code here if they click cancel or close
End If
End With

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

You might also like