VB.NET MySQL connection

后端 未结 2 710
无人共我
无人共我 2020-12-11 11:34

Can Visual Studio natively connect to a MySQL database or do I need to install a 3rd party connector first? Could someone please provide a small code example either way? I c

相关标签:
2条回答
  • 2020-12-11 11:55

    You can install the MySQL .NET connector from the following link

    http://dev.mysql.com/downloads/connector/net/

    and view a previous C# related answer of mine here:

    Connecting to a Mysql DB with C# - Need some with Datasets

    Sorry I dont have a VB related one but I'm sure you'd find plenty of examples here or on the web :P

    0 讨论(0)
  • 2020-12-11 11:57

    Can Visual Studio natively connect to a MySQL database?

    Based upon my knowledge, no.

    Do I need to install a 3rd party connector first?

    Yes, MySQL has their own .NET Connector.

    Could someone please provide a small code example either way? I can't seem to make this work.

    Here is the link to the MySQL Connector documentation..

    In there, I found this example:

    Imports System.Data
    
    Imports MySql.Data
    Imports MySql.Data.MySqlClient
    
    Public Class Tutorial1
        Public Shared Sub Main()
            Dim connStr As String = "server=localhost;user=root;database=world;port=3306;password=******;"
            Dim conn As New MySqlConnection(connStr)
            Try
                Console.WriteLine("Connecting to MySQL...")
                conn.Open()
            Catch ex As Exception
                Console.WriteLine(ex.ToString())
            End Try
            conn.Close()
            Console.WriteLine("Done.")
        End Sub
    End Class
    
    0 讨论(0)
提交回复
热议问题