Results 1 to 6 of 6

Thread: [2008] loop through database reocords

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    [2008] loop through database reocords

    how do i loop through all the records in a database? I have tried just adding 1 to the autonumber combobox but it only supports text so it doesnt work. i have tried converting it to a string then converting it back but this also doesnt work. is there a command to cycle through a the records?

    if anyone can offer some help i would be greatful. thanks

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] loop through database reocords

    Start with an ADO.NET tutorial. It's not the answer to your question but will help you gain an understanding of ADO.NET and how to work with databases.

    Once you do that you can, for example, get a dataset and populate your combobox with the records you want to show.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] loop through database reocords

    i dont have a problem connecting to the db or cycling through it (manualy) i just want to do it with code.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] loop through database reocords

    What code do you have so far? How are you getting your data?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] loop through database reocords

    i used the combobox's datasource and display member property to get the info from the database. there really isnt any code that loads the database because i used teh DB conection wizard built into VB to add it to my project.
    Last edited by bagstoper; May 9th, 2008 at 04:26 PM.

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

    Re: [2008] loop through database reocords

    If you've already got the data in a DataTable then you simply loop through the rows it contains. For a typed DataTable, which you will have if you created a Data Source, then you can use the properties specific to your data, e.g.
    vb.net Code:
    1. For row As MyDataTableRow In myDataSet.MyDataTable
    2.     MessageBox.Show(row.Name, row.ID.ToString())
    3. Next row
    If you have a standard DataTable, or if you prefer to do it this way with a typed DataTable, then you would use the standard members:
    vb.net Code:
    1. For row As DataRow In myDataSet.Tables("MyDataTable").Rows
    2.     MessageBox.Show(CStr(row("Name")), row("ID").ToString())
    3. Next row
    You will obviously have to use different names appropriate to your own project.
    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

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