c# - catching exception. error using stored procedure -
i have been working on web application project , while changing sql commands stored procedures security, code started catching exception. tried placing debug point on catch statement , shows
"index outside bounds of array."
i don't know how solve this.
try { string tw1 = textboxtowerno.text; landview.activeviewindex = 0; int aninteger = convert.toint32(textboxtowerno.text); int aninteger1 = aninteger - 1; int aninteger2 = aninteger + 1; lbltowerno.text = tw1; string connetionstring = system.configuration.configurationmanager .connectionstrings["constr"].connectionstring; ; sqlconnection cnn = new sqlconnection(connetionstring); string sql = "usp_select_tower_data"; cnn.open(); sqlcommand command = new sqlcommand(sql, cnn); command.commandtype = commandtype.storedprocedure; command.parameters.add("@tower", sqldbtype.nvarchar, 50,"username").value = tw1; sqldatareader datareader = command.executereader(); if (datareader.hasrows) { while (datareader.read()) { tower.text = datareader.getvalue(0).tostring(); latitude.text = datareader.getvalue(1).tostring(); longitude.text = datareader.getvalue(2).tostring(); survey.text = datareader.getvalue(3).tostring(); police.text = datareader.getvalue(7).tostring(); agri.text = datareader.getvalue(8).tostring(); village.text = datareader.getvalue(4).tostring(); taluka.text = datareader.getvalue(5).tostring(); district.text = datareader.getvalue(6).tostring(); hiddenlatt.value = datareader.getvalue(1).tostring(); hiddenlongi.value = datareader.getvalue(2).tostring(); } } else { scriptmanager.registerclientscriptblock(this, this.gettype(), "alertmessage", "alert('please enter correct tower number')", true); landview.activeviewindex = -1; } } catch (exception ex) { scriptmanager.registerclientscriptblock(this, this.gettype(), "alertmessage", "alert('error while getting data ')", true); landview.activeviewindex = -1; }
Comments
Post a Comment