Results 1 to 6 of 6

Thread: [2005] Loading data on datagridview

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    274

    [2005] Loading data on datagridview

    VB Code:
    1. Dim dbReader As OleDbDataReader = dbCommand.ExecuteReader
    2.              ComboBox1.Items.Clear()
    3.  
    4.             While (dbReader.Read)
    5.              ComboBox1.Items.Add(dbReader("PatientID"))
    6.  
    7.              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....
    Last edited by aldrean; Jun 22nd, 2006 at 08:55 PM. Reason: typo error

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    274

    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?

  4. #4
    Addicted Member
    Join Date
    Jan 2007
    Posts
    138

    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?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. myControl.DataSource = myDataSet.Tables("table name here")
    or indirectly:
    vb.net Code:
    1. myControl.DataMember = "table name here"
    2. myControl.DataSource = myDataSet
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Addicted Member
    Join Date
    Jan 2007
    Posts
    138

    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:
    1. myControl.DataSource = myDataSet.Tables("table name here")
    or indirectly:
    vb.net Code:
    1. myControl.DataMember = "table name here"
    2. myControl.DataSource = myDataSet
    ok got it. Thanx.

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