[2005] Loading data on datagridview
VB Code:
Dim dbReader As OleDbDataReader = dbCommand.ExecuteReader
ComboBox1.Items.Clear()
While (dbReader.Read)
ComboBox1.Items.Add(dbReader("PatientID"))
End While
I am using this code to load the combobox with all PatientID on a certain table of my access database.It was doing fine and now want to load the data in a datagridview.how can I possibly do this?One more thing, what if I also want to load the Name("PatientName") in the grid along with its ID?thanks in advance....
Re: [2005] Loading data on datagridview
If you want to dispay data in a grid then I suggest that you don't use a data reader. I'd suggest using a data adapter to Fill a DataTable and then simply assign the DataTable to the grid's DataSource property.
Re: [2005] Loading data on datagridview
i had tried using the wizard for the grid's datasource, using the dataset as my source, I just find it too slow to load the grid(about 8seconds) for a merely 20K records.Did it really had to be that long?That is the reason why I wanted for another option, or somebody can please let me know how can I possibly minimize the loading time?
Re: [2005] Loading data on datagridview
Quote:
Originally Posted by jmcilhinney
If you want to dispay data in a grid then I suggest that you don't use a data reader. I'd suggest using a data adapter to Fill a DataTable and then simply assign the DataTable to the grid's DataSource property.
instead of assigning the datasource to DataTable .. is it ok to assign the datasource to DataSet?
Re: [2005] Loading data on datagridview
Quote:
Originally Posted by mizee
instead of assigning the datasource to DataTable .. is it ok to assign the datasource to DataSet?
Do you actually understand what a DataSet is? A DataSet is not a substitute for a DataTable. A DataSet cannot be of any use unless it contains one or more DataTables because it's the DataTables that contain the data. You ALWAYS have to bind your controls to a DataTable one way or another. If your DataTable is in a DataSet then you can bind it directly:
vb.net Code:
myControl.DataSource = myDataSet.Tables("table name here")
or indirectly:
vb.net Code:
myControl.DataMember = "table name here"
myControl.DataSource = myDataSet
Re: [2005] Loading data on datagridview
Quote:
Originally Posted by jmcilhinney
Do you actually understand what a DataSet is? A DataSet is not a substitute for a DataTable. A DataSet cannot be of any use unless it contains one or more DataTables because it's the DataTables that contain the data. You ALWAYS have to bind your controls to a DataTable one way or another. If your DataTable is in a DataSet then you can bind it directly:
vb.net Code:
myControl.DataSource = myDataSet.Tables("table name here")
or indirectly:
vb.net Code:
myControl.DataMember = "table name here"
myControl.DataSource = myDataSet
ok got it. Thanx.