Hi, I would like to be helped with automating my application. I work in an environment where we receive a high number of files daily. I am given a task to read a file extract strings and compare them with data in mysql database. I use visual studio 2010. Here's my code:

Imports System
Imports System.Data
Imports MySql.Data.MySqlClient
Module Module1

Sub Main(ByVal args As String())
    Dim FILE_NAME As String = "C:\Users\LebohangL\Desktop\Lebo\DEND001D"
    Dim TextLine As String = Nothing
    Dim num As Integer = 0
    Dim strDate As String = Nothing
    Dim processing_date As String = Nothing
    Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
    Dim service_type As String = Nothing
    Dim serv_type As String = Nothing
    Dim executeDA As MySqlDataAdapter
    Dim datacombo As DataTable
    Dim myConnection As MySqlConnection
    Dim MySQLConnectionString As String
    MySQLConnectionString = "Server=localhost;" & _
                        "Database=lebo_test;" & _
                        "Userid=root;" & _
                        "Password=12345;"
    myConnection = New MySqlConnection(MySQLConnectionString)



    datacombo = New DataTable
    Dim sqlcmd = "SELECT processing_date, service_type from cleanup where service_type LIKE 'AD%'"

    executeDA = New MySqlDataAdapter(sqlcmd, myConnection)
    datacombo.Clear()
    executeDA.Fill(datacombo)

    Dim dtRow As DataRow

    For Each dtRow In datacombo.Rows
        service_type = dtRow("service_type")
        processing_date = dtRow("processing_date")

    Next



    If System.IO.File.Exists(FILE_NAME) = True Then


        Dim objReader As New System.IO.StreamReader(FILE_NAME)

        Do While objReader.Peek() <> -1
            num += 1
            TextLine = objReader.ReadLine()

            If num = 1 Then
                strDate = TextLine.Substring(2, 8)
                service_type = TextLine.Substring(10, 4)
            End If
        Loop


        Console.WriteLine("FileDate is: " + strDate)

        Console.WriteLine("Processing date is: " + processing_date)

        If strDate.ToString <> processing_date.ToString Then


            Console.WriteLine("Error 02! Invalid processing date ")

        Else

            Console.WriteLine("File Valid")
            Console.WriteLine("Service type is: " + service_type)
        End If
    End If

    Console.Read()
End Sub

End Module

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.