Datagrid收费查看遍历数据读取器 [英] chargement du datagridview a travers datareader

查看:80
本文介绍了Datagrid收费查看遍历数据读取器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通行证通行证通行证. Je veus afficher lesdonnéesd''un datareader dans un datagridview j''ai ecris le suivant:

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:

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

推荐答案

如果不能真正正确地理解您的要求,但是代码的问题是您无法直接绑定到DataReader,则需要使用阅读器创建一个DataTable,然后将网格绑定到DataTable ,就像这样

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

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.


这篇关于Datagrid收费查看遍历数据读取器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆