[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
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.
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.
Re: [2008] loop through database reocords
What code do you have so far? How are you getting your data?
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.
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.