VB.net から、MySQLへの接続
1,Download and install the latest .NET Framework SDK.
2,Install Microsoft Data Access Components (MDAC) 2.6 or later. MDAC 2.7 is recommended.
3,Install ODBC.NET Provider.
4,MySQLのインストール
5,Now install MySQL ODBC Driver-MyODBC
6,コントロールパネルにてODBCの設定
Microsoft.Data.Odbc.dllを参照します。
Imports Microsoft.Data.Odbc
Dim MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" + _
"SERVER=localhost;" + _
"DATABASE=test;" + _
"UID=;" + _
"PASSWORD=;" + _
"OPTION=3"
Dim MyConnection As New OdbcConnection(MyConString)
MyConnection.Open()
'Dim cmd As New Microsoft.Data.Odbc.OdbcCommand("insert into test values ('今日は')", MyConnection)
Dim cmd As New Microsoft.Data.Odbc.OdbcCommand("select * from test", MyConnection)
'DataReaderを使うselectなら
Dim reader As Microsoft.Data.Odbc.OdbcDataReader
reader = cmd.ExecuteReader()
While reader.Read()
Console.WriteLine(reader.GetString(0))
End While
' always call Close when done reading.
reader.Close()
''DataSetを使うselectなら
'Dim adapter As New Microsoft.Data.Odbc.OdbcDataAdapter(cmd)
'Dim ds As New DataSet()
'adapter.Fill(ds)
'結果を返さないSQL文なら
'cmd.ExecuteNonQuery()
MyConnection.Close()