asp.net - {"Object reference not set to an instance of an object."} -
creating asp.net form c#, facing error don't know error it. doing fine when push save button gives me error:
nulllrefrenceexception unhandled user code {"object reference not set instance of object."} object reference not set instance of object.
code:
protected void button8_click(object sender, eventargs e) { sqlconnection cnn = new sqlconnection(); cnn.connectionstring = system.configuration.configurationmanager.connectionstrings["sqladdsave"].connectionstring; cnn.open(); sqlcommand cmd = new sqlcommand(); cmd.commandtext = "select * displaypp"; cmd.connection = cnn; sqldataadapter da = new sqldataadapter(); da.selectcommand = cmd; dataset ds = new dataset(); da.fill(ds, " displaypp "); sqlcommandbuilder cb = new sqlcommandbuilder(da); datarow drow = ds.tables["displaypp"].newrow(); drow["website"] = web.text; drow["country"] = dropdownlist1.selecteditem.text; drow["contact"] = textbox144.text; drow["cat"] = textbox145.text; drow["traff"] = textbox146.text; more text boxes above ds.tables["displaypp "].rows.add(drow); da.update(ds, " displaypp "); string script = @"<script language=""javascript""> alert('information have been saved successfully.......!!!!!.'); </script>;"; page.clientscript.registerstartupscript(this.gettype(), "myjscript1", script); }
please help.
connection string:
<add name="sqladdsave" connectionstring="data source=(localdb)\v11.0;attachdbfilename=|datadirectory|\pptabledisplay.mdf;integrated security=true" providername="system.data.sqlclient" />
exception
exception details: system.nullreferenceexception unhandled user code hresult=-2147467261 message=object reference not set instance of object. source=testcrole stacktrace: @ testcrole._default.button8_click(object sender, eventargs e) in c:\users\xxxxx\documents\visual studio 2012\projects\windowsazure2\testcrole\default.aspx.cs:line 60 @ system.web.ui.webcontrols.button.raisepostbackevent(string eventargument) @ system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) innerexception:
ds.tables["displaypp "].rows.add(drow);
should this
ds.tables["displaypp"].rows.add(drow);
Comments
Post a Comment