所以我一直试图弄清楚为什么我的登录系统没有工作。是否有一个逻辑教程在线我可以看到有人制作一个?或者你们可以帮我解决这个问题吗? :(对不起,第一次在Vb中使用SQL。顺便说一句,它是一个远程托管的SQL服务器。
代码:
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class Form1
Dim conn As MySqlConnection
Private Sub ReconButton1_Click(sender As System.Object, e As System.EventArgs) Handles ReconButton1.Click
Dim conn As MySqlConnection
conn = New MySqlConnection()
conn.ConnectionString = "server=Host; user id=User; password=Pass; database=DB"
'see if connection failed
Try
conn.Open()
Catch myerror As MySqlException
MsgBox("Error connecting to server", MsgBoxStyle.Exclamation, "Error")
End Try
'sql query
Dim myAdapter As New MySqlDataAdapter
Dim sqlquery = "SELECT [] FROM users WHERE username = '" + TxtBox1.Text + "' AND password = '" + TxtBox2.Text + "'"
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
'start query
myAdapter.SelectCommand = myCommand
`It highlights myAdapter.SelectCommand = myCommand`
Dim mydata As MySqlDataReader
mydata = myCommand.ExecuteReader()
'see if user exist
If mydata.HasRows = 0 Then MsgBox("Invalid Login!") Else MsgBox("Login Accepted!")
Welcome.Show()
Me.Close()
End Sub
答案 0 :(得分:0)
我注意到了一些事情......
现在你有几个选择......
在线连接字符串与本地连接字符串没有区别。只需将serverip部件替换为“在线”服务器的公共IP地址即可。此外,如果它是默认实例,那么只有ip会为你做,但如果它是用户定义的实例,那么你也必须提到ip \ instance名称。
例如replace:server = Host ... To this ...
server=124.553.546.65 'Your server IP, this is only an example