プロが教えるわが家の防犯対策術!

お世話になります。
vb2005でmysqlに接続するにはどのように
コーディングすればよろしいのでしょうか?

教えてください。お願いします。

A 回答 (6件)

#2さん


ありがとうございます。

私は.NETは2002を利用しております。
.NET2005をDLしたのですが、まだインストールしておりません^^;

MySQL用のクラスが配布されていたのですねー
知りませんでした。
fortranxpさん。ありがとうございます。
ありがたい情報ですm(_ _)m


わたしもちょっとだけ調べたので、参考URLを張っておきますー
http://www.vbstation.net/tips/mysql_conn.htm

タメになりました^^
    • good
    • 0

#2 #4です。


どうも#4の例でも釈然としないので最終版です。
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports MySql.Data.MySqlClient

rem ここはPublic Class Form1を切り取ってimports以下をタイプしたあと貼り付けるとうまくいった。)

Public Class Form1

Inherits System.Windows.Forms.Form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Cn As MySqlConnection = New MySqlConnection

Cn = New MySqlConnection("Server=localhost;User ID=xxxxx;Password=xxxxx;Initial Catalog=MySQL")
Cn.Open()


Dim sqlSelect As New MySqlCommand("SELECT * FROM test", Cn)
Dim Adapter As New MySqlDataAdapter(sqlSelect)

Dim Table As New DataTable
Adapter.Fill(Table)

DataGrid1.DataSource() = Table

End Sub
End Class

参考URL:http://homepage1.nifty.com/MADIA/vb/vb_bbs/20030 …
    • good
    • 0

1050YENさんご指摘ありがとう。


それではこの方法があります。
http://www.gdncom.jp/general/bbs/ShowPost.aspx?P …

どうも2003Standard版では制約があります。
SQL ServerやAccessなら問題ないのに。。。。

でこの場合のポイントはhttp://www.mysql.com/products/connector/net/
net-connectorをダウンロードしますがページの右上

のRelated Pages:よりDownload Binaries & Sourceへ
飛びます。
またimportsがうまくいかないかも。(誰かおしえて~)

参考URL:http://www.gdncom.jp/general/bbs/ShowPost.aspx?P …
    • good
    • 0

#2さん


>AxDataGrid1
はVB6が入ってないと使えませんよ^^;

.NETのDataGridはデータビューと連結させます

なので、単なるADOを利用するのではなく、ADO.NETを利用しましょう。
http://okweb.jp/kotaeru.php3?q=1583980
    • good
    • 0

わたしはVB2003.NETですが


1.VB6のDataGridにMySQLのselect文の結果を表示する。
2.ADOを使用する。


Dim Cnxn2 As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Open a connection using a DSN and ODBC tags
Cnxn2 = New ADODB.Connection
rs = New ADODB.Recordset

Cnxn2.ConnectionString = "DSN=MySQL;UID=root;PWD=pass;"
Cnxn2.Open()
rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic

rs.Open("select * from test order by a asc", Cnxn2)

AxDataGrid1.DataSource() = rs

rs.ActiveConnection = Nothing
Cnxn2.Close()

End Sub

参考URL:http://hpcgi1.nifty.com/MADIA/VBBBS/wwwlng.cgi?p …
    • good
    • 0
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!