如果执行这个语句返回的值大于0
说明数据库中存在此用户
首先你本地要安装MySQL Connector Net
工程引用mysql.data
连接数据库:
Imports MySql.Data
Imports MySql.Data.MySqlClient
‘连接字符串dbServerName 是ip,下面的英文应该懂得吧。
dim sA as string
sA = "server=" &Me.dbServerName &"port=3306database=" &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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)