'งั้น check ด้วย HasRow ดูค่ะ
'ดึงมาแค่ 2 column คือ item(0),item(1)
SqlSelect = "SELECT TOP 1 idname ,password FROM [admin_teadher] WHERE
....
....
OleDataReader OleReader = OleCommand.ExecuteReader()
If OleReader.HasRows Then
While OleReader.Read
'get user info
'Checked ว่า ตรงกันหรือไม่
str_idname = OleReader.GetString(0) 'idname
str_password = OleReader.GetString(1) 'password
....
....
End While
Else
'ใส่ interface แจ้งเตือน ว่า ไม่พบ user ค่ะ
End If
If Cnn.State = ConnectionState.Open Then
Conn.Close()
End If
Cnn.ConnectionString = Cnnstring
SqlSelect = "Select Count(*) From [admin_teacher] Where [idname]=@idname And [Password]=@password"
Dim OleCommand As OleDbCommand = New OleDbCommand(SqlSelect, Cnn)
OleCommand.Parameters.Add("@idname", OleDbType.VarChar).Value = txtUserName.Text
OleCommand.Parameters.Add("@password", OleDbType.VarChar).Value = txtPassword.Text
Cnn.Open()
Dim LoginSuccess As Integer = CInt(OleCommand.ExecuteScalar())
Cnn.Close()
If LoginSuccess > 0 Then
frmLogin2.Show()
txtUserName.Text = ""
txtPassword.Text = ""
Me.Hide()
Else
'Do something
End If