vb.net - VB: Object variable or With block variable not set - why? -
i trying vb app write database if check box selected simple 1 indicate yes, rows in db set 0. seems line of code pointing , suggesting 'object variable or block variable not set' complete newbie thing...
sqlcomm.parameters.addwithvalue("@cbselect", cbselect.checked) 'passing @chkbox parameter command
here code behind.
protected sub button3_click(byval sender object, byval e system.eventargs) handles button3.click each gvrow gridviewrow in gridview1.rows 'itterate tru rows dim chkbox checkbox = ctype(gvrow.findcontrol("cbselect"), checkbox) 'find checkbox inside gridview dim sqlcon new sqlconnection("data source=syd-pb0fw9m\blah;initial catalog=support_metrics;persist security info=true;user id=reportserver;password=xxxxxxxx") dim sqlcomm new sqlcommand("insert contacted values (@cbselect)", sqlcon) 'this insert example, can update can current gridview row id using gvrow.cells(0).text sqlcomm.parameters.addwithvalue("@cbselect", cbselect.checked) 'passing @cbselect parameter command using (sqlcon) sqlcon.open() 'open connection sqlcomm.executenonquery() 'execute command end using next end sub
here aspx:
<columns> <asp:commandfield showselectbutton="false" /> <asp:templatefield> <itemtemplate> <asp:checkbox id="cbselect" runat="server" checked="false" /> </itemtemplate> </asp:templatefield> <asp:boundfield datafield="account_id" headertext="account_id" sortexpression="account_id" />
well, looking @ code here seem trying call property of object you're not instantiating. believe in code mean calling
sqlcomm.parameters.addwithvalue("@cbselect", chkbox.checked)
Comments
Post a Comment