MySQL & VB.NET

Posts 1–8 of 8 · Page 1 of 1
MySQL & VB.NET
how do I link vb express with an online database and to use it in the code( now started MySQL)

I tryed it but it failed..

a vi ideo or something be nice ty
What do you want done with MySQL?
Quote Originally Posted by Lolland View Post
What do you want done with MySQL?
i really dont kno...start with.. any the.




@ JASON so i only do ip or i will have to use ###IP###/BLA/SQLHERE
Firstly you need the .dll to reference MySQL in VB, then reference it and Import MySQL.Data.MySQLClient

Next, you need the appropriate connection string to your MySQL database:
Code:
Public SQLConnection As New MySqlConnection("server=serverIPHere;" & "user id=MySQLUsername;" & "password=databasePW;" & "database=databasename")
Then you need a connection procedure, with appropriate error handling:

Code:
    Public Sub TryConnect()

        Try
            SQLConnection.Open()
        Catch ex As Exception
            If MessageBox.Show("An error occurred when trying to connect to the database, would you like to try again?", "Database error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Yes Then
                TryConnect()
            Else
                Application.Exit()
            End If
        End Try

    End Sub
And that's about it, the connection is now open. You can execute database commands such as these two:

Code:
Dim cmdStr As String = "SELECT * FROM DevStudents ORDER BY StudentName ASC"
Dim sqlCMD As New MySqlCommand(cmdStr, SQLConnection)

        Try
            Using sRead As MySqlDataReader = sqlCMD.ExecuteReader
                Do Until sRead.Read = False

                    Dim sName As String = sRead("StudentName")
                    Dim sEmail As String = sRead("Email")
                    '...rest of my procedure here, but you dont need to know that'
                Loop
        End Try
Will simply select all rows from the "DevStudents" datatable and order them in ascending order according to "StudentName" column.

This one is a non query:

Code:
Dim UpdateStr As String = "UPDATE DevStudents SET Classes='" & outstr & "' WHERE ID='" & student.ID & "'"
Dim UpdateCMD As New MySqlCommand(UpdateStr, SQLConnection)
UpdateCMD.ExecuteNonQuery()
Will update the database according to my specifications.
You only use the IP as host.
Quote Originally Posted by Blubb1337 View Post
You only use the IP as host.
then iwillneed help
Mind speaking (understandable) English?
Quote Originally Posted by Blubb1337 View Post
Mind speaking (understandable) English?
I am on a PS3 ,srry .

I will need help when i get internet back on my computer. I tried to connect to a SQL and I got problems
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?