在Datagridview复选框值中保存在数据库验证时不为空 [英] in Datagridview checkbox value not to be null while saving in the database validating
问题描述
验证未在datagridview中检查的复选框,这些记录不应保存在数据库中。
在保存按钮代码中如下;
i在保存按钮中写上面的代码。
for(int i = 0 ; i< DGv_Session.RowCount; i ++)
{
尝试
{
if(DGv_Session [1 ,i] .Value!= null && DGv_Session [1,i] .Value!=&& DGv_Session [2,i] .Value!= null && DGv_Session [2,i] .Value!=&& DGv_Session [3 ,i] .Value!= null && DGv_Session [3,i] .Value!=&& DGv_Session [4,i] .Value!= null && DGv_Session [4,i] .Value!=)
{
sql =插入Tb_Session_Structure([Cmn_Minor_code],[Days],[Session1],[Session2],[Session3],[Session4]);
sql = sql +values(''+ cb_Course_Code.Text +'',
''+ DGv_Session.Rows [i] .Cells [0] .Value.ToString()+'',
+(Convert.ToBoolean(DGv_Session [1 ,i] .Value)== true).ToString()+,
+(Convert.ToBoolean(DGv_Session [2,i] .Value)== true).ToString()+ ,
+(Convert.ToBoolean(DGv_Session [3,i] .Value)== true).ToString()+,
+(转换。 ToBoolean(DGv_Session [4,i] .Value)== true).ToString()+);
GFun.Error =;
GFun.InsertAccessData (sql);
if(GFun.Error.ToString()!=)
{
MessageBox.Show(GFun.Error) .ToString(),错误);
返回;
}
GFun.OleDbCon.Close();
}
}
catch(例外情况)
{
MessageBox.Show(ex.ToString (),错误);
返回;
}
}
我正在验证未在datagridview中检查的复选框,该值不会保存在数据库中。
第1天2
1 checkboxunchecked checkboxunchecked
2 checkboxchecked checkboxchecked
<将上述记录输入数据库并单击保存按钮后输入
。
在数据库记录中显示如下;
第1天2
1 checkboxunchecked checkboxunchecked
2 checkboxchecked checkboxchecked
但是我想要在datagridview中没有选中哪个复选框不会保存在数据库中。
我想要输入后的最终输出如下点击数据库中的保存按钮记录,如下所示;
最终输出如下;
第1天2
2 checkboxchecked checkboxchecked
var chkboxFlag =
( input:checkbox [id
= chkfro m])。是( :检查跨度>);
if (!chkboxFlag)
{
return 请从列表中选择至少1项添加;
}
validating checkbox which are not checked in the datagridview those record should not be save in the database.
In Save Button code as follows;
i written the above code in the save button.
for (int i = 0; i < DGv_Session.RowCount; i++)
{
try
{
if (DGv_Session[1, i].Value != null && DGv_Session[1, i].Value != "" && DGv_Session[2, i].Value != null && DGv_Session[2, i].Value != "" && DGv_Session[3, i].Value != null && DGv_Session[3, i].Value != "" && DGv_Session[4, i].Value != null && DGv_Session[4, i].Value != "")
{
sql = "insert into Tb_Session_Structure ([Cmn_Minor_code],[Days],[Session1],[Session2],[Session3],[Session4])";
sql = sql + " values(''" + cb_Course_Code.Text + "'',
''" + DGv_Session.Rows[i].Cells[0].Value.ToString() + "'',
" + (Convert.ToBoolean(DGv_Session[1, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[2, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[3, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[4, i].Value) == true).ToString() + ")";
GFun.Error = "";
GFun.InsertAccessData(sql);
if (GFun.Error.ToString() != "")
{
MessageBox.Show(GFun.Error.ToString(), "Error");
return;
}
GFun.OleDbCon.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error");
return;
}
}
I am validating check box which are not checked in the datagridview that value not to be saved in the database.
Days 1 2
1 checkboxunchecked checkboxunchecked
2 checkboxchecked checkboxchecked
after enters the above records into the database and click the save button.
In the database records show as follows;
Days 1 2
1 checkboxunchecked checkboxunchecked
2 checkboxchecked checkboxchecked
but i want which checkbox which which are not checked in the datagridview do not be saved in the database.
I want the final output as follows after made entries and click the save button records in the database as follows;
Final ouput as follows;
Days 1 2
2 checkboxchecked checkboxchecked
var chkboxFlag=
("input:checkbox[id
=chkfrom]").is(":checked"); if(!chkboxFlag) { return "Please select atleast 1 item from the list to add"; }
这篇关于在Datagridview复选框值中保存在数据库验证时不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!