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

Recommended Answers

All 7 Replies

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

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

Maybe check the spelling first?

sqlCMD.ExecuteScalar()

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

(no diffene)

It is .Execute with a t not .Execule

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.