sql - looping through all records on the database -


i revised code little friend

but display first record how able manipulate loop through records

anyone give correct answer in code receive bounty thanks

note: displayofficeequipmentlist() sub displays data on database textboxes , comboboxes

public sub displayofficeequipmentlist()         dim sqlconn new sqlclient.sqlconnection         sqlconn.connectionstring = "server = skpi-apps1;" & _         "database = eoems;integrated security=true"          dim dt new datatable          sqlconn.open()         dim da new sqldataadapter("select * tblofficeequipmentprofile", sqlconn)         da.fill(dt)         cmbcategory.text = dt.rows(0)("oe_category").tostring()         cmbsubcategory.text = dt.rows(0)("oe_subcategory").tostring()         txtoeid.text = dt.rows(0)("oe_id").tostring()         txtname.text = dt.rows(0)("oe_name").tostring()         txtuser.text = dt.rows(0)("oe_user").tostring()         cmbbrand.text = dt.rows(0)("oe_brand").tostring()         cmbmodel.text = dt.rows(0)("oe_model").tostring()         txtspecs.text = dt.rows(0)("oe_specs").tostring()         txtserialno.text = dt.rows(0)("oe_serialno").tostring()         txtpropertyno.text = dt.rows(0)("oe_propertyno").tostring()         txtmacaddress.text = dt.rows(0)("oe_macaddress").tostring()         txtstaticip.text = dt.rows(0)("oe_static_ip").tostring()         txtvendor.text = dt.rows(0)("oe_vendor").tostring()         dtppurchasedate.text = dt.rows(0)("oe_purchasedate").tostring()         txtwarrantystatus.text = dt.rows(0)("oe_warrantystatus").tostring()         txtwarrantyinclusiveyear.text = dt.rows(0)("oe_warrantyinclusiveyear").tostring()         txtstatus.text = dt.rows(0)("oe_status").tostring()         cmbdeptcode.text = dt.rows(0)("oe_dept_code").tostring()         cmblocationcode.text = dt.rows(0)("oe_location_code").tostring()         txtremarks.text = dt.rows(0)("oe_remarks").tostring()         sqlconn.close()     end sub  private sub btnnext_click(byval sender system.object, byval e system.eventargs) handles btnnext.click        private sub btnprevious_click(byval sender system.object, byval e system.eventargs) handles btnprevious.click      end sub 

you have loop lines, getting values of row @ index 0( 1 row).

use foreach:

foreach (system.data.datarow row in dt.rows) {   //get values of row } 

edit: in vb.net this:

for each filarow datarow in dt.rows             dim oe_id string = filarow("oe_id").tostring             dim txtname string = filarow("oe_name").tostring next 

by way, seems filling textboxes, values change @ next loop. maybe should use control listbox


Comments