in combobox how do can i select the user as student not other

e.g. if the user is student not Manager

Private Sub loginform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim conn As New System.Data.OleDb.OleDbConnection()
    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"

    Try

        Dim sqlcmd As String = "SELECT * FROM tbl_datain"
        Dim sqlCom As New System.Data.OleDb.OleDbCommand(sqlcmd)

        sqlCom.Connection = conn
        conn.Open()

        Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()

        While sqlRead.Read()

            cbinfo.Items.Add(sqlRead("Personl").ToString)

        End While
        conn.Close()

    Catch ex As Exception

    End Try

End Sub

Private Sub cbinfo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbinfo.SelectedIndexChanged

    Dim conn As New System.Data.OleDb.OleDbConnection()
    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"

    Try

        Dim sqlcmd As String = "SELECT * FROM tbl_datain WHERE Personl ='" & cbinfo.Text & "'"
        Dim sqlCom As New System.Data.OleDb.OleDbCommand(sqlcmd)

        sqlCom.Connection = conn
        conn.Open()

        Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader("Personl")

        While sqlRead.Read()


            txtname.Text = sqlRead.ToString("UserID")
            txtpass.Text = sqlRead.ToString("PassWord")

            cbinfo.Text = ""
            txtname.Text = ""

            cbinfo.Focus()

            MessageBox.Show("Wong student")


        End While
        conn.Close()

    Catch ex As Exception

    End Try
End Sub
Attachments Slide2.JPG 50.56 KB Slide1.JPG 64.82 KB

Thinkless codification.
I do here some modification.
Your codes should be

Try
        Dim sqlcmd As String = "SELECT Count(*) FROM tbl_datain WHERE Personl ='" & cbinfo.Items(cbinfo.SelectedIndex) & "' " & _
        "And UserID ='" & txtname.Text & "' And PassWord ='" & txtpass.Text & "'"
        Dim sqlCom As New System.Data.OleDb.OleDbCommand(sqlcmd)
        sqlCom.Connection = conn
        conn.Open()
        Dim Result As Integer = sqlCom.ExeculeScalar()
        sqlCom.Dispose()
        conn.Close()

        if Result>0 then 
            'Do Here your process to save the attendence
            'of that student.

            MessageBox.Show("Present")

        Else
            MessageBox.Show("Wrong Input")
        End If

    Catch ex As Exception
    End Try
the sqlCom.ExeculeScalar() 
have Error (Value of type 'System.Data.OleDb.OleDbDataReader' cannot be converted to 'Integer'.)    

i have change to reader but dose not work at all

Edited 2 Years Ago by Xiao_1

*****Remove the parenthesis from sqlCom.ExeculeScalar().
write it as sqlCom.ExeculeScalar.*****

(no diffene)

This article has been dead for over six months. Start a new discussion instead.