在 System.FormatException 中第一次偶然出现的“mscorlib.dll”类型的异常

时间:2022-08-22 20:32:28
各位大哥,快来帮我看看,程序段如下:
private void tlbtnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                SqlDataAdapter sda = sqlclass.sqlsda("select * from tb_Personnel where EmployeeID=" + this.txtEmployeeID.Text);
                DataSet ds = new DataSet();
                SqlCommandBuilder sb = new SqlCommandBuilder(sda);
                sda.Fill(ds, "tb_Personnel");

                ds.Tables["tb_Personnel"].Rows[0]["Booker"] = this.txtBooker.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeAddress"] = this.txtEmployeeAddress.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeAge"] = this.txtEmployeeAge.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeCollege"] = this.txtEmployeeCollege.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeIDcard"] = this.txtEmployeeIDcard.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeKultuLevel"] = this.cbbEmployeeKultuLevel.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeLongSuit"] = this.txtEmployeeLongSuit.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeMobileTel"] = this.txtEmployeeMobileTel.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeName"] = this.txtEmployeeName.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeNativePlace"] = this.txtEmployeeNativePlace.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeOther"] = this.txtEmployeeOther.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeResume"] = this.txtEmployeeResume.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeSpeciality"] = this.txtEmployeeSpeciality.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeTel"] = this.txtEmployeeTel.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeUnitWorkAge"] = this.txtEmployeeUnitWorkAge.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeWorkAge"] = this.txtEmployeeWorkAge.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeBasePay"] = this.txtEmployeeBasePay.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeDept"] = this.cbbEmployeeDept.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeDutyType"] = this.cbbEmployeeDutyType.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeFolk"] = this.cbbEmployeeFolk.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeMarriage"] = this.cbbEmployeeMarriage.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeePoliticsVisage"] = this.cbbEmployeePoliticsVisage.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeePostTitle"] = this.cbbEmployeePostTitle.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeSex"] = this.cbbEmployeeSex.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeWorkType"] = this.cbbEmployeeWorkType.Text;
                ds.Tables["tb_Personnel"].Rows[0]["BookInTime"] = this.dtpBookInTime.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeBirth"] = this.dtpEmployeeBirth.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeePartyTime"] = this.dtpEmployeePartyTime.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeeFoldTime"] = this.dtpEmployeeFoldTime.Text;
                ds.Tables["tb_Personnel"].Rows[0]["EmployeePhoto"] = bytes;
                sda.Update(ds, "tb_Personnel");
                ds.Dispose();
                this.Bind();
                MessageBox.Show("数据修改成功!");
            }
            catch
            {
                MessageBox.Show("数据修改失败!");
            }
        }

4 个解决方案

#1


  ds.Dispose();
  this.Bind();

bind中出错吗?

#2


注意数据类型

  ds.Tables["tb_Personnel"].Rows[0]["BookInTime"] = this.dtpBookInTime.Text;
  ds.Tables["tb_Personnel"].Rows[0]["EmployeeBirth"] = this.dtpEmployeeBirth.Text;
  ds.Tables["tb_Personnel"].Rows[0]["EmployeePartyTime"] = this.dtpEmployeePartyTime.Text;
  ds.Tables["tb_Personnel"].Rows[0]["EmployeeFoldTime"] = this.dtpEmployeeFoldTime.Text;

这些是否是日期时间类型,如果是的话,那么你右边的TEXT这些内容,换成日期时间类型(比如DateTime.Parse(..Text); ) 再赋值给Rows[0]["字段"]。

其他的bool,byte[]等等都式样的道理。

#3


http://topic.csdn.net/u/20100501/09/fc8d003e-6bd9-4773-84f6-da638f81541d.html
先确定异常发生在哪行,然后像楼上说的有些可能需要进行类型转换.

#4


还是弹出数据修改不成功,然后是:system.data.dll异常

#1


  ds.Dispose();
  this.Bind();

bind中出错吗?

#2


注意数据类型

  ds.Tables["tb_Personnel"].Rows[0]["BookInTime"] = this.dtpBookInTime.Text;
  ds.Tables["tb_Personnel"].Rows[0]["EmployeeBirth"] = this.dtpEmployeeBirth.Text;
  ds.Tables["tb_Personnel"].Rows[0]["EmployeePartyTime"] = this.dtpEmployeePartyTime.Text;
  ds.Tables["tb_Personnel"].Rows[0]["EmployeeFoldTime"] = this.dtpEmployeeFoldTime.Text;

这些是否是日期时间类型,如果是的话,那么你右边的TEXT这些内容,换成日期时间类型(比如DateTime.Parse(..Text); ) 再赋值给Rows[0]["字段"]。

其他的bool,byte[]等等都式样的道理。

#3


http://topic.csdn.net/u/20100501/09/fc8d003e-6bd9-4773-84f6-da638f81541d.html
先确定异常发生在哪行,然后像楼上说的有些可能需要进行类型转换.

#4


还是弹出数据修改不成功,然后是:system.data.dll异常