Reputation: 145
I created a web form using asp.net and connect it to the table in SQL2012. I insert data to table with parameters in asp. Everything is ok but the checkboxes in the form, always pass false to the table and in the sql they data are always false (it's not different that they are checked or not, they pass false). The columns in sql have "bit" datatype for these checkboxes. Here is the code:
cmdObj.Parameters.AddWithValue("@host", host.Checked);
cmdObj.Parameters.AddWithValue("@domain", domain.Checked);
cmdObj.Parameters.AddWithValue("@needContent", needContent.Checked);
cmdObj.Parameters.AddWithValue("@CMS", CMS.Checked);
ASP.net Code:
<asp:CheckBox ID="host" runat="server" />
<asp:CheckBox ID="domain" runat="server" />
<asp:CheckBox ID="domain" runat="server" />
<asp:CheckBox ID="CMS" runat="server" />
Upvotes: 0
Views: 97
Reputation: 646
// Aboved Code looks works fine for me, even though Please find one more solution for you approach here.
cmdObj.Parameters.AddWithValue("@host", host.Checked==true?1:0);
cmdObj.Parameters.AddWithValue("@domain", domain.Checked==true?1:0);
cmdObj.Parameters.AddWithValue("@needContent", domain.Checked==true?1:0);
cmdObj.Parameters.AddWithValue("@CMS", CMS.Checked==true?1:0);
Upvotes: 1