gpt4 book ai didi

mysql - 使用 Visual Basic 的 SQL 连接错误 40 000webhost

转载 作者:行者123 更新时间:2023-11-29 20:37:04 25 4
gpt4 key购买 nike

我很确定我的所有信息都在这里,但我不断收到此错误

http://puu.sh/qoZDQ/7294d6e682.png

我使用的代码:(不是我的)

我有正确的用户名密码和数据库名称(我认为)

'SET THE CONNECTION BETWEEN VISUAL BASIC AND MYSQL DATABASE
Dim con As SqlConnection = New SqlConnection("Data Source=mysql9.000webhost.com;" & "Initial Catalog=databasename;" & "User ID=username;" & "Password=password;")

'A SET OF COMMAND IN MYSQL
Dim cmd As New SqlCommand
'SET A CLASS THAT SERVES AS THE BRIDGE BETWEEN A DATASET AND DATABASE FOR SAVING AND RETRIEVING DATA.
Dim da As New SqlDataAdapter
'SET A CLASS THAT CONSISTS SPECIFIC TABLE IN THE DATABASE
Dim dt As New DataTable
Dim sqlQuery As String
Dim result As Integer

Private Sub register(ByVal sqlQuery As String)
Try
'OPENING THE CONNECTION
con.Open()
'HOLDS THE DATA TO BE EXECUTED
With cmd
.Connection = con
.CommandText = sqlQuery
End With
'EXECUTE THE DATA
Result = cmd.ExecuteNonQuery
'CHECKING IF THE DATA HAS BEEN EXECUTED OR NOT
If result > 0 Then
MsgBox("User has been registered.")
Else
MsgBox("Failed to register the user.")
End If
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub login(ByVal sqlQuery As String)
Try
con.Open()
With cmd
.Connection = con
.CommandText = sqlQuery
End With
'FILLING THE DATA IN A SPECIFIC TABLE OF THE DATABASE
da.SelectCommand = cmd
dt = New DataTable
da.Fill(dt)
'DECLARING AN INTEGER TO SET THE MAXROWS OF THE TABLE
Dim maxrow As Integer = dt.Rows.Count
'CHECKING IF THE DATA IS EXIST IN THE ROW OF THE TABLE
If maxrow > 0 Then
MsgBox("Welcome " & dt.Rows(0).Item(4))
Else
MsgBox("Account does not exist.")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
End Sub

Private Sub btn_Register_Click(sender As Object, e As EventArgs) Handles btn_Register.Click
sqlQuery = "INSERT INTO `dbuser` ( `user_name`, `user_username`, `user_pass`, `user_type`, `user_steamid`)" & "VALUES ('" & txtname.Text & "','" & txtusername.Text & "','" & txtpassword.Text & "','" & cbotype.Text & "','" & txtsteamid.Text & "')"
register(sqlQuery)
End Sub

Private Sub btn_Login_Click(sender As Object, e As EventArgs) Handles btn_Login.Click
sqlQuery = "SELECT * FROM `dbuser` WHERE user_username ='" & txtusername.Text & "' AND user_pass = '" & txtpassword.Text & "'"
login(sqlQuery)
End Sub

我使用了这里的数据库信息http://puu.sh/qoZXo/a391cba854.jpg (也不是我的信息只是一个例子,所以我不会公开发布我的信息)

最佳答案

我在 Plutonix 评论的帮助下解决了我的问题

MySql is not the same thing as Microsoft SqlServer – Plutonix

所以我做了一些谷歌搜索,发现了这个:https://dev.mysql.com/downloads/connector/net/

这是 MySql 的 .Net 框架(我认为这是正确的术语)

无论如何安装这个然后更改我的代码的第一行

imports System.Data.SqlClient

致:

imports MySql.Data.MySqlClient

并将代码中的sql变量更改为MySql变量,只需将My添加到第一位,它似乎工作“更好”我现在有一个新问题,但它与000webhosts mysql数据库有关,而不是代码。

关于mysql - 使用 Visual Basic 的 SQL 连接错误 40 000webhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38755484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com