wpf - In combo box selection change, first selection returning all values as 0 and next selections returning the values of the previous row of the database -
i loading 1 combo box value database.
when selecting first option combo box, it's fetching other values 0, , when selecting next option combo box it's showing results of previous option
below code
this combo box
dim cmd new sqlcommand("select companyname company", conn) 'company name dim dt new datatable 'company name dim da new sqldataadapter(cmd) 'company name da.fill(dt) 'company name 'company name cmbcompanyname.itemssource = dt.defaultview cmbcompanyname.displaymemberpath = "companyname" cmbcompanyname.selectedvaluepath = "companyname"
and below 1 filling fields @ combo selection changed
try dim dt new datatable dim connection new sqlconnection("data source=kitt7-pc;initial catalog=project;user id=sa;password=1234") connection.open() dim cmd3 new sqlcommand("select * company companyname='" & cmbcompanyname.text & "'", connection) cmd3.executenonquery() dim da new sqldataadapter(cmd3) da.fill(dt) if dt.rows.count > 1 messagebox.show("more 1 record found company name") end if if dt.rows.count = 0 messagebox.show("no records found") exit sub end if cmbcompanycode.visibility = windows.visibility.hidden txtcompanycode.visibility = windows.visibility.visible cmbcomapnyalias.visibility = windows.visibility.hidden txtcompanyalias.visibility = windows.visibility.visible each dr datarow in dt.rows txtcompanycode.text = dt.rows(0)("companycode").tostring() ' txtcompanyname.text = dt.rows(0)("companyname").tostring() txtcompanyalias.text = dt.rows(0)("alias").tostring() txtaddress.text = dt.rows(0)("address").tostring() cmbcity.text = dt.rows(0)("city").tostring() txtpincode.text = dt.rows(0)("pincode").tostring() cmbstate.text = dt.rows(0)("state").tostring() txtcountry.text = dt.rows(0)("country").tostring()
please tell me problem.
in each loop referencing dt.rows(0)("something")
, aren't you?
i guess need change:
for each dr datarow in dt.rows txtcompanycode.text = dt.rows(0)("companycode").tostring() ' txtcompanyname.text = dt.rows(0)("companyname").tostring() txtcompanyalias.text = dt.rows(0)("alias").tostring()
to like
for each dr datarow in dt.rows txtcompanycode.text = dr ("companycode").tostring() ' txtcompanyname.text = dr ("companyname").tostring() txtcompanyalias.text = dr ("alias").tostring()
Comments
Post a Comment