首先,你用的不是sqlserver,而是access
其次
你把这句放出来
string sqlstr="update info set name='"+name.Text+"',age="+age.Text+",gender="+gender.Text+",jiguan='"+jiguan.Text+"',tel="+tel.Text+" where id ="+e.Item.Cells[0].Text+";";
而且帮你稍作了修改,int类型的不用加'',char类型的要加''
把这句注释起来
//string sqlstr="update info set name=?,age=?,gender=?,jiguan=?,tel=? where id = "+e.Item.Cells[0].Text;
试试

解决方案 »

  1.   

    void DataGrid1_Update(object sender,DataGridCommandEventArgs e)
           {
           string name,gender,jiguan,tel,age;
           
           TextBox txtname,txtage,txtgender,txtjiguan,txttel;
           txtname=(TextBox)e.Item.Cells[1].Controls[0];
           txtage=(TextBox)e.Item.Cells[2].Controls[0];
           txtgender=(TextBox)e.Item.Cells[3].Controls[0];
           txtjiguan=(TextBox)e.Item.Cells[4].Controls[0];
           txttel=(TextBox)e.Item.Cells[5].Controls[0];
           name=txtname.Text;
           age=txtage.Text;
           gender=txtgender.Text;
           jiguan=txtjiguan.Text;
           tel=txttel.Text;
           string dbpath=@"student.mdb";
           string connstr="PROVIDER=Microsoft Jet OLEDB.4.0;DATA Source="+Server.MapPath(dbpath)+";";
           OleDbConnection myconn=new OleDbConnection(connstr);
           string sqlstr="update info set [name] = '"+name+"',age ='"+age+"',gender ='"+gender+"',jiguan ='"+jiguan+"',tel ='"+tel+"' where id ="+e.Item.Cells[0].Text;
           
           OleDbCommand mycommupt=new OleDbCommand(sqlstr,myconn);
           myconn.Open();
           mycommupt.ExecuteNonQuery();
           myconn.Close(); 
           DataGrid1.EditItemIndex =-1;
           bind();       }我改成上面这样,点更新的时候----
    异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。参数名: index源错误: 
    行 80:        
    行 81:        TextBox txtname,txtage,txtgender,txtjiguan,txttel;
    行 82:        txtname=(TextBox)e.Item.Cells[1].Controls[0];
    行 83:        txtage=(TextBox)e.Item.Cells[2].Controls[0];
    行 84:        txtgender=(TextBox)e.Item.Cells[3].Controls[0];谁帮帮我