VB.Net/Database ADO.net/MySQL

Материал из VB Эксперт
Версия от 12:44, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

MySQL Connection String

Imports System
Imports System.Data
Imports MySql.Data.MySqlClient

Module MySqlConnect
   Sub Main()
      Dim connString As String = "Database=Test;Data Source=localhost;User Id=root;Password=mypassword"
      Dim conn As New MySqlConnection(connString)
      Try
         conn.Open()
         Console.WriteLine("Connection Opened")
         Console.WriteLine("Connection Properties")
         Console.WriteLine("- ConnectionString : {0}", conn.ConnectionString)
         Console.WriteLine("- Database : {0}", conn.Database)
         Console.WriteLine("- DataSource : {0}", conn.DataSource)
         Console.WriteLine("- ServerVersion : {0}", conn.ServerVersion)
         Console.WriteLine("- State : {0}", conn.State)
      Catch ex As MySqlException
         " Display error
         Console.WriteLine("Error: " & ex.ToString())
      Finally
         " Close Connection
         conn.Close()
         Console.WriteLine("Connection Closed")
      End Try
   End Sub
End Module


MySql.Data.MySqlClient Demo

Imports System
Imports System.Data
Imports MySql.Data.MySqlClient

Module MySqlConnect
   Sub Main()
      Dim connString As String = "Database=Test;Data Source=localhost;User Id=root;Password=mypassword"
      Dim conn As New MySqlConnection(connString)
      Try
         conn.Open()
         Console.WriteLine("Connection Opened")
         Console.WriteLine("Connection Properties")
         Console.WriteLine("- ConnectionString : {0}", conn.ConnectionString)
         Console.WriteLine("- Database : {0}", conn.Database)
         Console.WriteLine("- DataSource : {0}", conn.DataSource)
         Console.WriteLine("- ServerVersion : {0}", conn.ServerVersion)
         Console.WriteLine("- State : {0}", conn.State)
      Catch ex As MySqlException
         " Display error
         Console.WriteLine("Error: " & ex.ToString())
      Finally
         " Close Connection
         conn.Close()
         Console.WriteLine("Connection Closed")
      End Try
   End Sub
End Module