用户代码未处理 System.FormatException
  Message="输入字符串的格式不正确。"
  Source="mscorlib"
  StackTrace:
       在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
       在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
       在 System.Convert.ToInt32(String value)
       在 Default2.Button1_Click(Object sender, EventArgs e) 位置 f:\复选框\Default2.aspx.cs:行号 25
       在 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       在 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       在 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
代码在这里:
SqlConnection cond = new SqlConnection("Server=.;database=yy;uid=sa;pwd=sa;");
                cond.Open();
                
                SqlCommand comd = new SqlCommand("update prolike set likenum=likenum+1 where id="+Convert.ToInt32(this.CheckBoxList1.DataValueField)+"", cond);-----结果在这里显示出错
                comd.ExecuteNonQuery();
                cond.Close();

解决方案 »

  1.   

    SqlConnection con = new SqlConnection(
                    @"Server=(local);User=sa;PWD=111;Database=test");不知道楼主那样写是不是有问题,这个给参考一下
      

  2.   

    看看this.CheckBoxList1.DataValueField是数字字符串吧
      

  3.   

    SqlCommand comd = new SqlCommand("update prolike set likenum=likenum+1 where id="+Convert.ToInt32(this.CheckBoxList1.DataValueField)+"", cond);-----结果在这里显示出错改成
    SqlCommand comd = new SqlCommand("update prolike set likenum=likenum+1 where id="+Convert.ToInt32(this.CheckBoxList1.DataValueField), cond);试试
    前提是this.CheckBoxList1.DataValueField里面的值要保证是数字
      

  4.   

    public static int ToInt32 ( string value)异常类型 条件 
    FormatException     value 不是由一个可选符号后跟数字序列(0 到 9)组成的。
     
      

  5.   

    Convert.ToInt32(this.CheckBoxList1.DataValueField)的问题...怎么能这样用?楼主想实现什么目的?得到选中checkbox的DataValueField的值?
      

  6.   

    this.CheckBoxList1.DataValueField是你自己绑定的一个字段名...又怎么能转成Int型呢?