Results 1 to 7 of 7

Thread: [2005] Read From A Dataset Instead Of DataReader

  1. #1

    Thread Starter
    Addicted Member skea's Avatar
    Join Date
    Mar 2006
    Posts
    187

    [2005] Read From A Dataset Instead Of DataReader

    Dear Folks,
    i created this thread because i got no help on something setting me back that i presented in another thread. In that thread, someone suggested that i use a dataset instead of a Datareader.
    I am trying to populate a form using a DataReader....how can i populate my form by simply using a dataset.
    You will excuse me, i know how to create one,fill it and use it but i dont know how to populate each control on my form with a corresponding field of the record accessed by the dataset.

    Any Idea will be highly appreciated.

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

    Re: [2005] Read From A Dataset Instead Of DataReader

    Add a BindingSource to your form in the designer. The following steps can be done in the designer or in code.

    Bind your DataTable to the BindingSource using its DataSource and, optionally, DataMember properties. The BindingSource now acts a way to view the data in the table.

    Bind your controls to the BindingSource using their DataBindings property, e.g.
    VB Code:
    1. myTextBox.DataBindings.Add("Text", myBindingSource, "ColumnName")
    You can now set the Position property of the BindingSource to a record index and every bound control will update. You can then get a DataRowView object for the current record through the Current 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
    Addicted Member skea's Avatar
    Join Date
    Mar 2006
    Posts
    187

    Re: [2005] Read From A Dataset Instead Of DataReader

    Thanks JMC...i wish databindings were better for me!! Alas...i have never liked using them aand i dont use them at all. Is there any other way?

  4. #4

    Thread Starter
    Addicted Member skea's Avatar
    Join Date
    Mar 2006
    Posts
    187

    Re: [2005] Read From A Dataset Instead Of DataReader

    I am taking a chatter to a remote location i will be back online in an 1 and 1/2 hrs time.

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

    Re: [2005] Read From A Dataset Instead Of DataReader

    Quote Originally Posted by skea
    Thanks JMC...i wish databindings were better for me!! Alas...i have never liked using them aand i dont use them at all. Is there any other way?
    Of course: do it all manually. It's up to you, but you're asking how to populate your controls so that implies you wanted some of the work done for you. If that's not the case then just set the appropriate properties as you normally would. Data binding IS the automatic way. If you don't like using them then don't. Plain and simple.
    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
    Lively Member mikelynch's Avatar
    Join Date
    May 2006
    Location
    Goombungee Qld
    Posts
    83

    Post Re: [2005] Read From A Dataset Instead Of DataReader

    Quote Originally Posted by skea
    Dear Folks,
    i created this thread because i got no help on something setting me back that i presented in another thread. In that thread, someone suggested that i use a dataset instead of a Datareader.
    I am trying to populate a form using a DataReader....how can i populate my form by simply using a dataset.
    You will excuse me, i know how to create one,fill it and use it but i dont know how to populate each control on my form with a corresponding field of the record accessed by the dataset.

    Any Idea will be highly appreciated.
    Dont know if this helps but you could do it a bit more manually like this , but it still uses the DataSet.

    VB Code:
    1. For intX = 0 To (intRecordCount - 1)
    2.        intAccountID = dsCustomers.Tables(0).Rows(intX).Item("pkAccountID")
    3.      strFamilyName = dsCustomers.Tables(0).Rows(intX).Item("fldFamilyName")
    4.      strFirstName =  dsCustomers.Tables(0).Rows(intX).Item("fldFirstName")
    5.      strPCode = dsCustomers.Tables(0).Rows(intX).Item("fldPCode")
    6.        
    7.         Next

  7. #7

    Thread Starter
    Addicted Member skea's Avatar
    Join Date
    Mar 2006
    Posts
    187

    Re: [2005] Read From A Dataset Instead Of DataReader

    Thanks mikeLynch. i never knew it was that simple.
    JMC...thanks too.

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