Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2010-03-06
If it is in your control, stay with SQL Server! If it isn’t, this is how you can do it.
When you install the .NET Connector for MySQL, a class library called MySql.Data is installed. You can add a reference to it from the Add Reference dialog. This gives you a new set of classes for accessing a MySQL database. This is what a connection to a database can look like:
Dim ConnectionString As String = "Server=XXX;Port=3306;Database=XXX;Uid=XXX;Pwd=XXX" Using Cn As New MySql.Data.MySqlClient.MySqlConnection(ConnectionString) Cn.Open() Console.WriteLine(Cn.State.ToString()) Cn.Close() End Using
If you know you ADO.NET, the rest should be a stroll in the park. This code lists keywords in MySQL:
Dim ConnectionString As String = "Server=XXX;Port=3306;Database=mysql;Uid=XXX;Pwd=XXX" Using Cn As New MySql.Data.MySqlClient.MySqlConnection(ConnectionString) Cn.Open() Using Cmd As New MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM help_keyword", Cn) Dim R As MySql.Data.MySqlClient.MySqlDataReader = Cmd.ExecuteReader() While R.Read() Console.WriteLine(R.GetString(1)) End While R.Close() End Using Cn.Close() End Using
Categories: Visual Basic 9
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
[…] posted here: Connecting to MySQL from Visual Basic – WinSoft.se Posted in Uncategorized | Tags: class-library, connector, from-the-add, net, new-set, […]
Wiersz Poleceń Windows CMD…
Windows XP Vosten SP3 PRO 2010 released now! this windows combining the beauty of appearance and the advanced performance, The System has been updated completely with the latest updates and hotfixes from Microsoft to maintain the highest level of secur…