如何与mysql localhost进行vb连接 [英] how to do the connection vb with mysql localhost
问题描述
(我以登录表格填写)
导入MySql.Data.MySqlClient
公共课程表格1
Dim conn As String ="Driver = {MySQL}; SERVER = localhost; DATABASE = mydb;"
公共子retriveData()
试试
昏暗的连接作为新的MySqlConnection(conn)
昏暗的cmd作为新的MySqlCommand
connection.Open()
昏暗的阅读器为MySqlDataReader
reader = cmd.ExecuteReader()
而reader.Read()
Console.WriteLine((reader.GetString(0)&,"& _
reader.GetString(1)))
结束时
reader.Close()
connection.Close()
异常捕获
Console.WriteLine(ex.Message)
结束尝试
结束子
End Class
一次打开连接(在您需要创建的帮助器类中).
之后,在整个应用程序期间使用该连接.
hai, anyone can help me. how do i connect this code with mysql localhost using wamp server and insert data in database. is this code should be written on each form to connect to the database or there is another solution to help.
(i write in login form)
Imports MySql.Data.MySqlClient
Public Class Form1
Dim conn As String = "Driver={MySQL};SERVER=localhost;DATABASE=mydb;"
Public Sub retriveData()
Try
Dim connection As New MySqlConnection(conn)
Dim cmd As New MySqlCommand
connection.Open()
Dim reader As MySqlDataReader
reader = cmd.ExecuteReader()
While reader.Read()
Console.WriteLine((reader.GetString(0) & ", " & _
reader.GetString(1)))
End While
reader.Close()
connection.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Class
Open the connection once (in a helper class that you need to create).
After that, use that connection across the duration of the application.
这篇关于如何与mysql localhost进行vb连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!