i'm having problem data set. i'm using 1 populate text boxes of form. user selects value search from, press button , text boxes populated. works fine first record want page through them. i've declared data set used other methods when gets paging returned rows keep getting object reference error. can shed light on i'm going wrong?
declaring variables:
//creates global dataset copies table dataset datasethm; //create default row values int maxrows = 0; int inc = 0;
the connection database , filling data set:
protected void executeselectcopies(string sname) { sqlconnection connection = new sqlconnection(getconnectionstring()); string sql = "select tblcopies.copyid, tblsoftware.softwarename, tblcopies.assetname, tblcopies.location," + " tblcopies.licencekey, tblcopies.oem, tblcopies.state, tblcopies.installationdate" + " tblcopies" + " inner join tblsoftware on tblcopies.softwareid = tblsoftware.softwareid" + " tblsoftware.softwarename = @softwarename" + " order tblcopies.copyid"; sqldataadapter adapterhm = new sqldataadapter(); sqlcommand select = new sqlcommand(sql, connectionhm); adapter.selectcommand = select; select.parameters.add(new sqlparameter("@softwarename", sname)); //open connection connectionhm.open(); datasethm = new dataset(); adapterhm.fill(datasethm, "copies"); navigatecopies(); maxrows = datasethm.tables["copies"].rows.count; connectionhm.close(); }
the method filling text boxes:
private void navigatecopies() { datarow drow = datasethm.tables["copies"].rows[inc]; textboxcopyid.text = drow.itemarray.getvalue(0).tostring(); textboxsoftwarename.text = drow.itemarray.getvalue(1).tostring(); dropdownlistassetname.selecteditem.text = drow.itemarray.getvalue(2).tostring(); dropdownlistlocation.selecteditem.text = drow.itemarray.getvalue(3).tostring(); textboxlicence.text = drow.itemarray.getvalue(4).tostring(); dropdownlisttype.selecteditem.text = drow.itemarray.getvalue(5).tostring(); dropdownliststate.selecteditem.text = drow.itemarray.getvalue(6).tostring(); textboxinstall.text = drow.itemarray.getvalue(7).tostring(); }
and button next record:
protected void buttonnext_click(object sender, eventargs e) { if (inc != maxrows - 1) { inc++; navigatecopies(); } else { messagebox.show("no more rows"); } }
any appreciated. can't understand why data set works navigation method not second. i've been using http://www.homeandlearn.co.uk/csharp/csharp_s12p7.html guide, example displays data on page load mine displayed when search parameter selected. don't know if problem bit more information never hurts!
persist dataset
in session/cache/viewstate (which ever 1 of these applicable solution you). way can retrieve dataset
between postback's , continue display data required.
here how accomplish this (albeit simple example) , article delves object persistence within asp.net: asp.net object persistence.
Comments
Post a Comment