|
-
June 10th, 2002, 04:37 PM
#1
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
-
June 12th, 2002, 01:54 PM
#2
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
-
June 12th, 2002, 02:07 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|