Code: Select all
Imports CoreLab.MySql
Imports System.IO
Module DataTable
Sub Main()
Dim strFileName As String = "C:\Export.txt"
Dim intLoop As Integer
Dim strString As String
Dim strSql As String
' Delete the file if it exists.
If File.Exists(strFileName) Then
File.Delete(strFileName)
End If
'Create the file.
Dim objFileOpen As FileStream = File.Create(strFileName)
Dim objFileWrite As StreamWriter = New StreamWriter(objFileOpen)
'Build table
strSql = "SELECT AssociateNumber, CardNumber, NameFirst, NameLast, Department, JobCode FROM Associate"
Dim dtAssociate As MySqlDataTable = New MySqlDataTable(strSql, "Host=localhost;Port=3306;User ID=root;Password=$4JBDev@ds;Database=Express")
Try
dtAssociate.Active = True
For intLoop = 0 To dtAssociate.Rows.Count - 1
strString = dtAssociate.Rows(intLoop)(0).ToString.PadLeft(12) & "," & _
dtAssociate.Rows(intLoop)(1).ToString.PadLeft(2, "0") & "," & _
dtAssociate.Rows(intLoop)(2).PadRight(14) & "," & _
dtAssociate.Rows(intLoop)(3).PadRight(20) & "," & _
dtAssociate.Rows(intLoop)(4).PadRight(10) & "," & _
dtAssociate.Rows(intLoop)(5).PadRight(6)
objFileWrite.WriteLine(strString)
Next
Finally
dtAssociate.Active = False
End Try
objFileWrite.Close()
End Sub
End Module