本文介绍了如何与mysql localhost进行vb连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai,任何人都可以帮助我.我该如何使用WAMP服务器将此代码与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

解决方案


这篇关于如何与mysql localhost进行vb连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 09:56