[英]SQL, VB.Net | What query can I use grab this value?
In the above I want it to give me the value of "ID" of the "Username" associated with it.在上面我希望它给我与它相关联的“用户名”的“ID”的值。
Here is the command I tried这是我试过的命令
Dim Query2 = String.Format("SELECT ID FROM account WHERE character = " & UsernameTextBox.Text & " ")
Command = New MySqlCommand(Query2, mydbcon)
Dim idtest = reader.Read.ToString
MsgBox(idtest)
however it is returning "false" what am I doing wrong?但是它返回“假”我做错了什么?
Here is the entire code that I am working on:这是我正在处理的整个代码:
Try
mydbcon.Open()
Dim Query As String
Query = String.Format("SELECT * FROM account WHERE username = '{0}' AND password = '{1}'", Me.UsernameTextBox.Text.Trim(), Me.PasswordTextBox.Text.Trim())
Dim Command = New MySqlCommand(Query, mydbcon)
reader = Command.ExecuteReader
Dim count As Integer
count = 0
While reader.Read
count = count + 1
End While
If count = 1 Then
MessageBox.Show("Username and password are correct")
Query = String.Format("SELECT username AS ID FROM account WHERE character = " & UsernameTextBox.Text & " ")
Command = New MySqlCommand(Query, mydbcon)
My.Settings.LoginID = reader.Read
MsgBox(My.Settings.LoginID)
ElseIf count > 1 Then
MessageBox.Show("Username and password are duplicate")
Else
MessageBox.Show("Username and password are wrong")
End If
mydbcon.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
mydbcon.Dispose()
End Try
使用 ID 作为别名(因此select username AS anyNameYouWantToAssignToIt
):
Dim Query2 = String.Format("SELECT username AS ID FROM account WHERE character = " & UsernameTextBox.Text & " ")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.