Click here to Skip to main content
16,007,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
je travaille sur une base de données access. je veus afficher les données d'un datareader dans un datagridview j'ai ecris le code suivant:
VB
cnxstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\compaq\Desktop\Emploi.mdb;"
       cnx = New OleDb.OleDbConnection
       cnx.ConnectionString = cnxstr
       cnx.Open()


       Dim myReader1 As OleDb.OleDbDataReader = cmd1.ExecuteReader

       sql1 = select salle, jour, HD  from etudiant where filiere="'&combobox1.selecteditem &"'"
      
       cmd1 = New OleDb.OleDbCommand

       cmd1.Connection() = cnx
       cmd1.CommandText = sql1

     Dim myreader As OleDb.OleDbDataReader = cmd1.ExecuteReader
       If myReader.HasRows = True Then
           MsgBox("bien")

           While (myReader.HasRows)
               DataGridView1.DataSource = myReader

                  End While
             Else
                   MsgBox("nooooooooooooooon")
           End While
       End If
       cnx.Close()
j'ai verifié que la datareader contient des données mais j'arrive pas à les affiché sur le datagrid.est ce que mon code monque quelques choses?
pouvez vous m'aider s'il vous plait.
merci d'avance
Posted
Comments
Sandeep Mewara 9-May-11 6:52am    
English please!

1 solution

If don't really understand correctly what you are asking, but the problem with the code is that you cannot bind directly to a DataReader, you would need to create a DataTable with the reader and then bind the grid to the DataTable, something like this

VB
Dim myreader As OleDb.OleDbDataReader = cmd1.ExecuteReader
        If myreader.HasRows = True Then
            MsgBox("bien")
            While (myreader.HasRows)
                Dim dt As DataTable = New DataTable()
                dt.Load(myreader)
                DataGridView1.DataSource = dt.DefaultView
            End While
        Else
            MsgBox("nooooooooooooooon")
        End If


Hope this helps.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-May-11 13:26pm    
I don't really understand this stuff, but it looks like you do understand some French. Tres bien. :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900