你在catch后加一个throw,把异常抛出来看看是什么原因

解决方案 »

  1.   

    可能在这,你可以不要用odbc
    string ConnString="data source=jzj;database=DataPlatform;user id=rs;pwd=rs";你可以
    catch(Exception ex)
    {
    Response.Write(ex.Message);
    }
      

  2.   

    打印出SQL语句到查询分析器中执行一下,看有无问题,再说
      

  3.   

    小弟对throw也不熟,麻烦大师再具体点,代码中如何加入?
      

  4.   

    try
    {
    myCommand.ExecuteNonQuery();
    DGPerson.EditItemIndex=-1;

    }
    catch
    {
                                         throw;
    Response.Redirect("error.aspx");
    }
    这样会把异常抛出来,等你调试好了再把这句删了,如果看了异常还不知是什么错,请你把异常信息贴出来。
      

  5.   

    错误提示如下:
    String was not recognized as a valid DateTime. 可能是myCommand.Parameters.Add(new SqlParameter("@CoTime",SqlDbType.DateTime,8));
          myCommand.Parameters.Add(new SqlParameter("@ITTime",SqlDbType.DateTime,8));     myCommand.Parameters[cols[i]].Value=colvalue;
    而colvalue是String 类型,各位大虾,我如何才能把datagrid上更新以后的datatime类型的值传回数据库呢?
      

  6.   

    你这样是不行的,DateTime的参数需要传入DateTime对象,而不是String
    所以你的代码里面凡是不是VarChar类型的参数,都不能用:
    myCommand.Parameters[cols[i]].Value=colvalue;
    这样赋值如果要赋DateTime的值,可以这样:
    myCommand.Parameters[X].Value = DateTime.Parsr( colvalue ); //X为某一参数索引
      

  7.   

    不好意思,应该是DateTime.Parse而不是DateTime.Parsr
      

  8.   

    for (int i=0;i<numCols-2;i++)
        {
         String colvalue=((TextBox)E.Item.Cells[i].Controls[0]).Text.ToString();
         if (4<i || i<7)
              myCommand.Parameters[cols[i]].Value=DateTime.Parse(colvalue);
         else 
    myCommand.Parameters[cols[i]].Value=colvalue;
        }
    我都如此改了,为什么还报同样的错误?谢谢!
      

  9.   

    这样
    你在
    myCommand.ExecuteNonQuery();这一句上下个断点调试看看,参数的值都设对了没有
      

  10.   

    for (int i=0;i<numCols-2;i++)
        {
         String colvalue=((TextBox)E.Item.Cells[i].Controls[0]).Text.ToString();
         if (4<i && i<7)
              myCommand.Parameters[cols[i]].Value=DateTime.Parse(colvalue);
         else 
    myCommand.Parameters[cols[i]].Value=colvalue;
        }
    我都如此改了,为什么还报同样的错误?谢谢!

      

  11.   

    错误提示:
    String was not recognized as a valid DateTime. 
    当执行到datetime类型时,
    myCommand.Parameters[cols[i]].Value=DateTime.Parse(colvalue);
    报错!
    另:小弟很菜,不知道调试的时候如何看等号两边的值,请教了!
      

  12.   

    哦,小弟调试出来了:
    问题可能是这样,我在数据库中的datime类型的两个字段皆为null,也就是执行到下面语句的时候colvalue为空!
    myCommand.Parameters[cols[i]].Value=DateTime.Parse(colvalue);是不是当colvalue为空的时候,就能不转换为DateTime类型??
      

  13.   

    对,null不能赋给DateTime你确定你的值是不是可以为空,如果可以为空的话,你就给参数赋DBNull.Value,这个常量代表数据库的空值
      

  14.   

    麻烦你再具体点,我数据库中,哪两个字段的确可以为空,那么我下面这条赋值语句应该如何给参数赋DBNull.Value才对?万分感谢!!!!
    myCommand.Parameters[cols[i]].Value=DateTime.Parse(colvalue);
      

  15.   

    if( colvalue==null )
      myCommand.Parameters[cols[i]].Value=DBNull.Value;
    else
      myCommand.Parameters[cols[i]].Value=DateTime.Parse(colvalue);
      

  16.   

    万分感谢你!另:我跟踪到当数据字段为空的时候,反映到datagrid的text值为"",所以上面的值得改为
    if( colvalue=="" )
      myCommand.Parameters[cols[i]].Value=DBNull.Value;
    else
      myCommand.Parameters[cols[i]].Value=DateTime.Parse(colvalue);程序终于通过了了!
    再次谢谢你 timmy3310(tim) !