新手学习checkbox问题?????
我在GridView中放入几个CheckBox,在更改时,总是提示异常详细信息: System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配。代码如下:: protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int Rid = Convert.ToInt32(((Label)GridView1.Rows[e.RowIndex].Cells[11].FindControl( "lblRid ")).Text);
string Rname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl( "txtRname ")).Text;
CheckBox OrderSend = (CheckBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl( "chkOrderSend ");
//CheckBox Production = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[3].FindControl( "chkProduction ")).Checked;
//CheckBox Product = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[4].FindControl( "chkProduct ")).Checked;
//CheckBox Material = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[5].FindControl( "chkMaterial ")).Checked;
//CheckBox Client = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[6].FindControl( "chkClient ")).Checked;
//CheckBox Provider = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[7].FindControl( "chkProvider ")).Checked;
//CheckBox Employee = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[8].FindControl( "chkEmployee ")).Checked;
//CheckBox Finance = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[9].FindControl( "chkFinance ")).Checked;
//CheckBox User = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[10].FindControl( "chkUser ")).Checked;
bool updateok;
//updateok = Convert.ToBoolean(DataOption.Option( "update [Role] set [Rname]= ' " + Rname + " ',[OrderSend]= ' " + OrderSend + " ' ,[Production]= ' " + Production + " ',[Product]= ' " + Product + " ',[Material]= ' " + Material + " ',[Client]= ' " + Client + " ',[Provider]= ' " + Provider + " ',[Employee]= ' " + Employee + " ',[Finance]= ' " + Finance + " ',[User]= ' " + User + " ' where Rid= " + Rid));
updateok = Convert.ToBoolean(DataOption.Option( "update [Role] set [Rname]= ' " + Rname + " ',OrderSend= ' " + OrderSend.Checked + " ' where Rid= " + Rid));
if (updateok == true)
{
GridView1.EditIndex = -1;
DataOption.Dispose();
this.BindToGridView();
}
}
我用bool代替checkbox也不行!当注释所在checkbox我就可以更新!???
我要如何做才好??????
[解决办法]
改成这样试试:
updateok = "update [Role] set [Rname]= ' " + Rname + " ',OrderSend= " + OrderSend.Checked? "-1 ": "0 " + " where Rid= " + Rid;
[解决办法]
哎,又一个没仔细看我代码的。
是/否型字段在SQL语句两边不要加单引号。
改成这样:
string Sql = "insert into Role(Rname,OrderSend) values( ' " + name + " ', " + OrderSend + ") ";