|
-
May 9th, 2008, 04:05 PM
#1
Thread Starter
Hyperactive Member
[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
-
May 9th, 2008, 04:13 PM
#2
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.
-
May 9th, 2008, 04:14 PM
#3
Thread Starter
Hyperactive Member
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.
-
May 9th, 2008, 04:20 PM
#4
Re: [2008] loop through database reocords
What code do you have so far? How are you getting your data?
-
May 9th, 2008, 04:21 PM
#5
Thread Starter
Hyperactive Member
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.
-
May 10th, 2008, 04:21 AM
#6
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:
For row As MyDataTableRow In myDataSet.MyDataTable MessageBox.Show(row.Name, row.ID.ToString()) 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:
For row As DataRow In myDataSet.Tables("MyDataTable").Rows MessageBox.Show(CStr(row("Name")), row("ID").ToString()) Next row
You will obviously have to use different names appropriate to your own project.
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
|