CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2001
    Location
    Minneapolis, MN, USA
    Posts
    150

    Exclamation DataReader to a DataGrid

    Hello!

    Does anyone have a clue on how to use DataReader to insert data into a DataGrid!? Is this worth figuring out OR should I just use a DataSet? I figured if I could use a DataReader on all data that would just be displayed and not editted...it would make my application more efficient. Is this true? OR are DataReaders basically just used with Web Forms? Please help!

    Thanks again!

    Code:
    Sub DisplayUnassignedOrders(ByVal frm As frmMain)
            cmdString = "spSELECTUnassignedOrders"
            SQLconn = New SqlConnection(connString)
    
            Dim cmdTemp As New SqlCommand(cmdString, SQLconn)
            Dim drTemp As SqlDataReader, dtTemp As DataTable, dsTemp As DataSet
            Dim obTemp As Object()
    
            SQLconn.Open()
            drTemp = cmdTemp.ExecuteReader(CommandBehavior.CloseConnection)
    
            If (drTemp.Read()) Then
                drTemp.Close()
                SQLconn.Open()
    
               drTemp = cmdTemp.ExecuteReader(CommandBehavior.CloseConnection)
                frm.DataGrid1.DataSource = drTemp
                frm.DataGrid1.DataBindings()
                'While (drTemp.Read())
                'frm.DataGrid1.DataBindings()
                'frm.DataGrid1.Item(0, 0) = drTemp.Item(0)
                    'MessageBox.Show(drTemp.Item(0))
                'End While
            Else
                MessageBox.Show("DataReader not available")
            End If
            drTemp.Close()
        End Sub

  2. #2
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    173

    Lightbulb

    The DataReader is a light-weight class that lets you quickly extract data (forward-only) from a command object.

    The DataSet privides broader functionality, including the ability to bind to a datagrid. You can create a read-only dataview for display-only data.

    Efficiency is relative. If a user has to wait 50 milliseconds for a screen to refresh versus 250 milliseconds for the same screen then you can say you have a 5-fold improvement in effeciency but who will notice? Is it worth the extra coding effort, the increased probability of bugs, and the increased difficulty of maintenance for those 200 milliseconds? It may be in some circumstances.

    DataReaders are handy for filling listboxes and combo-boxes with information that won't change. Datasets are handy when filtering, editing, and/or sorting are required. They are also handy for populating DataGrids.

    pjp
    Preston Park
    CTT+, MCT, MCSD
    http://www.prestonpark.com/

  3. #3
    Join Date
    Aug 2001
    Location
    Minneapolis, MN, USA
    Posts
    150

    Talking

    I hear ya... Just curious! Thanks for the response!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured