求一个vb.net链接mysql数据库的增删改查程序,求速度。。。 5
首先你本地要安装MySQL Connector Net
工程引用mysql.data
连接数据库:
Imports MySql.Data
Imports MySql.Data.MySqlClient
‘连接字符串dbServerName 是ip,下面的英文应该懂得吧。
dim sA as string
sA = "server=" & Me.dbServerName & "; port=3306; database=" & Me.dbDataBaseName & _
"; user id=" & Me.dbUserName & "; password=" & Me.dbPassWord & "; "
dim mvardbConnectionMysql As MySqlConnection
With mvardbConnectionMysql
.ConnectionString = sA
.Open()
End With
4. 读取数据
dim xx As MySqlDataReader
Dim oC As MySqlCommand = New MySqlCommand(sSql, Me.mvardbConnectionMysql)
oC.CommandType = CommandType.Text
xx= oC.ExecuteReader()
if xx.HasRows
do while xx.read() ’一次读取一行
msgbox xx.item(2) '取出当前行的第三个字段的值显示。
loop
end if
5. 写入数据
Dim oT As MySqlTransaction = Me.mvardbConnectionMysql.BeginTransaction()
Try
Dim oC As MySqlCommand
'下面的commandtext是执行的更新语句,例如Insert into 语句。
oC = New MySqlCommand(CommandText, Me.mvardbConnectionMysql, oT)
oC.CommandType = CommandType.Text
oC.ExecuteNonQuery()
oT.Commit()
oC = Nothing
oT = Nothing
Catch oe As Exception
oT.Rollback()
End Try
没看太懂,有没有做好的小实例啊给发一个,或者留个联系方式指导一下。