我找了很多关于这个问题的参考资料,但什么都没有。。它仍然有相同的错误,当我做登录,然后它将不会有任何问题,并在一段时间后,错误会显示这么多次。
Call Koneksi()
Try
cmd = New Odbc.OdbcCommand("SELECT * FROM tb_user WHERE username = '" & txt_username.Text & "' AND password = '" & txt_password.Text & "'", conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
txt_akses.Text = rd!hak_akses
MsgBox("Welcome '" & rd!nama & "'", MsgBoxStyle.Exclamation, "Information")
MenuCustomer.txt_user.Text = rd!username
cmd = New Odbc.OdbcCommand("SELECT * FROM tb_permainan WHERE status = 1", conn)
rd = cmd.ExecuteReader
rd.Read()
If txt_akses.Text = "Customer" Then
If rd.HasRows = False Then
txt_username.Text = ""
txt_password.Text = ""
txt_akses.Text = ""
MenuCustomer.Show()
Else
MsgBox("Permainan sedang berlangsung. Mohon Untuk login sesaat lagi", MsgBoxStyle.Exclamation, "Information")
End If
Else
MenuStaff.Show()
End If
Else
txt_username.Text = ""
txt_password.Text = ""
txt_akses.Text = ""
txt_username.Select()
MsgBox("Username atau password salah", MsgBoxStyle.Exclamation, "Information")
End If
rd.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
这是我的名为koneksi imports system.data.odbc的模块
Module CRUD
'Setting Koneksi
Public conn As OdbcConnection
Public cmd As OdbcCommand
Public ds As New DataSet
Public da As OdbcDataAdapter
Public rd As OdbcDataReader
Public dt As New DataTable
Public LokasiData As String
Public result As String
Sub Koneksi()
LokasiData = "Driver={MySQL ODBC 3.51 Driver};Database=db_bubble;server=192.168.1.14;uid=root"
conn = New OdbcConnection(LokasiData)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
End Sub
2条答案
按热度按时间xesrikrc1#
这个
DataReader.HasRows
属性检查必须在DataReader.Read()
方法,该方法应包含在While
循环因为DataReader
是只向前的流(在之后立即检查行可用性)ExecuteReader()
). 以下示例是正确的方法:请注意,您应该使用不同的
DataReader
示例,因为在当前代码中DataReader
赋值覆盖第一个。还可以在查询中使用参数来防止sql注入尝试。6ioyuze22#
我已经修改了我的代码这样,它仍然显示错误
显示的错误是循环。。