编号如果是自动增加的话,不用更新编号。
将strUpdate中编号去掉。

解决方案 »

  1.   

    这个问题一般是你的语句中的单引号错误,必须遵循
    update tablename set columnname='newvalue',注意如果newvalue不是数的时候,单引号必须有。你用变量也是这样SqlCommand cmd=new SqlCommand("update tablename set mnname='"+newvalue+"'");//这里的newvalue是个变量
    也可以这样用SqlCommand cmd=new SqlCommand("update tablename set columnname=@value",cnn);
    cmd.Parameters.Add("@value",yourvalue)
    推荐用后一种方法。
      

  2.   

    错误提示表明,你的sql语句在执行中有错误
    跟踪一下,看看like后面的值是什么?
      

  3.   

    sql语句中除了数字不用加'以外,像日期和字符串等都要加';如:
    update aaa set s1='2004-3-3',s2='dddd'.你的可能出现在这个地方:
    strUpdate+=",开始日期="+((TextBox)e.Item.Cells[4].Controls[0]).Text+"";
    改为
    strUpdate+=",开始日期='"+((TextBox)e.Item.Cells[4].Controls[0]).Text+"'";
    其它日期的类似
      

  4.   

    我最开始的时候是加了'的,可它说不能将char型转换为DateTime型的,可我在数据表里面定久了开始日期和结束日期为DateTime型的啊?这是怎么回事呢??怎么改才正确呢
      

  5.   

    其实你最好改用参数传入的方式,你之种方法很老土了 :)
    你用 Convert.ToDateTime((TextBox)e.Item.Cells[4].Controls[0]).Text) 试试
      

  6.   

    如果发生异常用 try catch
      

  7.   

    你是不是说这个意思:
    strUpdate+=",开始日期=Convert.ToDateTime((TextBox)e.Item.Cells[4].Controls[0]).Text);
      

  8.   

    你用什麼數據庫 ,如果是Access ,那麼時間類型要加#
    strUpdate+=",开始日期=#" ((TextBox)e.Item.Cells[4].Controls[0]).Text) &"#"
      

  9.   

    如果是Sql Server, 時間類型:
    strUpdate+=",开始日期=Convert.ToDateTime((TextBox)e.Item.Cells[4].Controls[0]).Text);
      

  10.   

    试试strUpdate+=",开始日期='"+Convert.ToDateTime(((TextBox)e.Item.Cells[4].Controls[0]).Text)+"'";
      

  11.   

    string strConn="server=xw;uid=sa;pwd=sa;database=Car";
    SqlConnection myConnection=new SqlConnection();
    myConnection.ConnectionString=strConn;
    string strCommand="select * from   保险情况表";
    //我增加了两行;
    SqlCommand oCommand= new SqlCommand(strCommand,myConnection);
    oCommand.CommandType = CommandType.Text;
    //*******SqlDataAdapter da=new SqlDataAdapter(strCommand,myConnection);
    DataSet ds=new DataSet();
    da.Fill(ds,"scores");
    DataGrid1.DataSource=ds.Tables["scores"].DefaultView;
    DataGrid1.DataBind();如果用存储过程,方法是:
    首先在SqlServer(看你的方法应该是使用SqlServer)的企业管理器下,先建立存储过程。(也就是把SQl语句按顺序写就去就行了。他有格式的。因为你这个语句很简单,没有什么条件判断,也没有参数传递,其实不用存储过程更简单),假设存储过程取名为findData;那么将刚才我增加的两句改为:
    SqlCommand oCommand = new SqlCommand("findData",myConnection);
    oCommand.CommandType = CommandType.StoreProcedure;
    就OK了!
      

  12.   

    另外那后面一句也要改:
    SqlDataAdapter da=new SqlDataAdapter(strCommand,myConnection);
    改为:
    SqlDataAdapter da = new SqlDataAdapter(oCommand);