我想提供" 1"选中复选框时的值和" 0"什么时候不检查。
但每当我选择一些复选框并尝试自动插入数据库时,所有选中的复选框都被选中,我得到数据库中的所有列,其中包含" 1"值。我正在使用Microsoft SQL Server 2014。
这是我的数据库中的表单和列的图像:
"Insert into UserPrivl values ('" + lboUsers.SelectedItem.ToString() + "', '"
+ (Convert.ToBoolean(chkCreateComp.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkSaveAs.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkAddControl.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditControl.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteControl.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteControl.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkAddIndi.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditIndi.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteIndi.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkPandLDef.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkBSDef.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkBudgetInfo.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkNewJournal.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditJournal.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteJournal.Checked = true) ? "1" : "0") + "','0','0','"
+ (Convert.ToBoolean(chkNewReceipt.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditReceipt.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteReceipt.Checked = true) ? "1" : "0") + "','0','"
+ (Convert.ToBoolean(chkNewPayment.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditPayment.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeletePayment.Checked = true) ? "1" : "0") + "','0','"
+ (Convert.ToBoolean(chkNewBankR.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditBankR.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteBankR.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkNewBankP.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditBankP.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteBankP.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkNewWithdrawl.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditWithdrawl.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteWithdrawl.Checked = true) ? "1" : "0") + "','0','"
+ (Convert.ToBoolean(chkNewDeposit.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditDeposit.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteDeposit.Checked = true) ? "1" : "0") + "','0','"
+ (Convert.ToBoolean(chkDaybook.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkJournalExplorer.Checked = true) ? "1" : "0") + "','0','0','"
+ (Convert.ToBoolean(chkStockGroup.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkAddStock.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditStock.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteStock.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkAddStockTran.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkEditStockTran.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkDeleteStockTran.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkTranReport.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkStockReport.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkSalesReport.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkPurchaseReport.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkChart.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkControlStat.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkTrialBal.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkBalanceUnderCon.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkVoucher.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkIndiStat.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkFinancialStat.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkBalList.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkUserReport.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkGraph.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkSearch.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkMissing.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkAudit.Checked = true) ? "1" : "0") + "','"
+ (Convert.ToBoolean(chkSysSet.Checked = true) ? "1" : "0") + "')");
答案 0 :(得分:1)
在这种情况下,您将始终将值1插入到表中,因为chkCreateComp.Checked = true
将始终评估为true
将此更改为条件等于运算符..(==)