asp.net insertCommand resulting in NULL values -
i have 2 listboxes values sent tablec via button.
<asp:sqldatasource id="sql1" runat="server" connectionstring="<%$ connectionstrings:connectiondatabase %>" selectcommand="select [name] + ' (' + [cnbr] + ')' fullname, [cnbr] cnum [tablea] order [name]"> </asp:sqldatasource> <asp:listbox id="lst1" runat="server" datasourceid="sql1" datatextfield="fullname" datavaluefield="cnum" autopostback="true"> </asp:listbox> <asp:sqldatasource id="sql2" runat="server" connectionstring="<%$ connectionstrings:connectiondatabase %>" insertcommand="insert [tableb] ([cnbr], [rdate]) values (@cnbr, @rdate)" <insertparameters> <asp:parameter name="cnbr" type="string" /> <asp:parameter name="rdate" type="datetime" /> </insertparameters> <asp:imagebutton id="ibncheckoutbtn" runat="server" imageurl="./images/vidcheckoutbutton.png" onclick="ibncheckoutbtn_click" />
aspx.cs file:
protected void ibnbtn_click(object sender, imageclickeventargs e) { sql2.insert(); }
i don't know c# , class doesn't cover c#, looking solution doesn't use lot of behind-code. error is:
cannot insert value null column 'cnbr', table 'tableb'; column not allow nulls. insert fails. statement has been terminated.
however, nulls should not occur because values taken populated listbox. help?
you need assign values sql2 insert parameters in similar way follows:
protected void ibnbtn_click(object sender, imageclickeventargs e) { sql2.insertparameters["cnbr"].defaultvalue = this.findcontrol("lst1").selectedvalue; sql2.insertparameters["rdate"].defaultvalue = datetime.now.tostring(); sql2.insert(); }
Comments
Post a Comment