if corrct this code it will come of the list in the datagridview in VB from access

this my code:

  Private Sub ComboBoxadm_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxadm.SelectedIndexChanged

        Dim conn As New System.Data.OleDb.OleDbConnection()
        conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\Database1.accdb"
        If conn.State = ConnectionState.Open Then conn.Close()
        conn.Open()
        Dim sql As String = "Select [Stud Admin] As [User Name], TimeIn, TimeOut From tbl_studentadm Where ProjectNo ='" & ComboBoxadm.Items(ComboBoxadm.SelectedIndex) & "'"
        Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql, conn)
        sqlCom.Connection = conn
        Dim sqlReader As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()
        If sqlReader.HasRows Then
            sqlReader.Read()
            DataGridView1.Text = (sqlReader.Item("[User Name]").ToString)
            DataGridView1.Text = (sqlReader.Item("TimeIn").ToString)
            DataGridView1.Text = (sqlReader.Item("TimeOut").ToString)

        End If
        sqlReader.Close()
        sqlCom.Dispose()
        conn.Close()

    End Sub
End Class

Edited 1 Year Ago by Xiao_1

Here's an example of adding data to a DataGridView with two columns.

Dim con As New SqlConnection("Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=yes;")
Dim cmd As New SqlCommand("", con)

cmd.CommandText = "SELECT au_lname, au_fname FROM authors WHERE city = 'Oakland'"

con.Open()

Dim rdr As SqlDataReader = cmd.ExecuteReader

Do While rdr.Read()
    DataGridView1.Rows.Add({rdr("au_lname"), rdr("au_fname")})
Loop

rdr.Close()
con.Close()
This question has already been answered. Start a new discussion instead.