Wednesday, November 10, 2010

Some Codes that might comes in handy

I want to share some of the codes i used for my Database migration tool. Here's some codes that you might need for your are creating a simple application.


Try
                    Dim di As DirectoryInfo = New DirectoryInfo("C:\tmpCLSWOBR")
                    di.Create()
                    System.IO.File.Copy(TextBox5.Text, "C:\tmpCLSWOBR\dbs_import.sql", True)
                    Dim csqlFile As New StreamWriter("C:\tmpCLSWOBR" & "\" & TextBox4.Text & ".sql")
                    csqlFile.WriteLine("drop database if exists " & TextBox4.Text & ";")
                    csqlFile.WriteLine("create database " & TextBox4.Text & ";")
                    csqlFile.WriteLine("use " & TextBox4.Text & ";")
                    csqlFile.Close()
                    Dim TextFile As New StreamWriter("C:\tmpCLSWOBR\create.bat")
                    TextFile.WriteLine("""C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe"" -h " & TextBox1.Text & " -u " & TextBox2.Text & " --password=" & TextBox3.Text & " < C:\tmpCLSWOBR\" & TextBox4.Text & ".sql""")
                    TextFile.WriteLine("""C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe"" -h " & TextBox1.Text & " -u " & TextBox2.Text & " --password=" & TextBox3.Text & " " & TextBox4.Text & " < C:\tmpCLSWOBR\dbs_import.sql""")
                    TextFile.Close()
                    Process.Start("C:\tmpCLSWOBR\create.bat")
                    MsgBox("SUCCESSFUL!")
Catch ex As Exception
                    MsgBox(ex.Message)
End Try




 Dim di As DirectoryInfo = New DirectoryInfo("C:\tmpCLSWOBR")
 di.Create()


- This line of code will create a folder named tmpCLSWOBR in drive C:

Dim TextFile As New StreamWriter("C:\tmpCLSWOBR\create.bat")
- This line of code is to create a .bat file. For some purposes...:)

TextFile.WriteLine("You Text in Here")
- This will be the line of input(text) that your going to insert in your .bat file
- To add newline in your .bat file you can just add the code above...(in short 2 codes 2 lines of text)...

1 comment:

  1. COMPNETS - M-T 10:30 - 12:00 4G Vega 321
    WED 04:00 - 07:00 Lab 2

    COMARTS4 W-TH 8:30 - 10:00 222 4E Tibong

    WORDLIT W-TH 10:00 - 11:30 421 4G Atillano

    ReplyDelete

IMG KO