sql server - Error while using label to query database -
i'm trying display rows in gridview match id cast label. error "input string not in correct format" when run query.
private sub bindgrid() dim constring string = configurationmanager.connectionstrings("connstr").connectionstring using con new sqlconnection(constring) using cmd new sqlcommand("select * [table] id=@label6") using sda new sqldataadapter() cmd.connection = con cmd.parameters.add("@label6", label.text) sda.selectcommand = cmd using dt new datatable() sda.fill(dt) gridview2.datasource = dt gridview2.databind() end using end using end using end using end sub
here code label:
public sub linkbutton1_click(sender object, e eventargs) dim lnk linkbutton = directcast(sender, linkbutton) label6.text = lnk.text linkbutton1_modalpopupextender.show() end sub
what doing wrong? id int.
the aspx code
<asp:linkbutton id="lnkdummy" runat="server"></asp:linkbutton> <cc1:modalpopupextender id="linkbutton1_modalpopupextender" runat="server" enabled="true" targetcontrolid="lnkdummy" popupcontrolid="panel1"> </cc1:modalpopupextender> <asp:panel id="panel1" runat="server" height="164px" width="284px" backcolor="slategray" ><br /><br /> <center><asp:label id="label6" runat="server" text="label"></asp:label><br /> <asp:gridview id="gridview2" runat="server" autogeneratecolumns="false" pagesize="2" allowpaging="true"> <columns> <asp:boundfield datafield="status" headertext="status" sortexpression="status" /> <asp:boundfield datafield="comments" headertext="comments" sortexpression="comments" /> <asp:boundfield datafield="processed_by" headertext="processed_by" sortexpression="processed_by" /> </columns> </asp:gridview> <asp:button id="button3" runat="server" cssclass="btn btn-default btn-md" text="close"/></center> </asp:panel>
there no overload of add
takes parameter name , value. change line:
cmd.parameters.add("@label6", label.text)
to this:
cmd.parameters.add("@label6", sqldbtype.int).value = label.text
Comments
Post a Comment