Click to See Complete Forum and Search --> : DataReader to a DataGrid


nolc
June 10th, 2002, 04:37 PM
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!


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

pjpark
June 12th, 2002, 01:54 PM
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

nolc
June 12th, 2002, 02:07 PM
I hear ya... Just curious! Thanks for the response!