0

使用此代码我没有错误消息。当我执行我的程序时,我遇到了一些错误“更新条目时发生错误。有关详细信息,请参阅内部异常。” 我的程序崩溃了。数据库不保存任何字段。

`Driver data = new Driver();
                     if (txtCallSign.Text != null)
                     {
                        data.callSign = Convert.ToInt32(txtCallSign.Text);
                     }
                    data.firstName = txtFirstName.Text;
                    data.middleName = txtMname.Text;
                    data.lastName = txtLastName.Text;
                    data.address1 = txtStreet.Text;
                    data.address2 = txtArea.Text;
                    data.address3 = txtCity.Text;
                    data.postCode = txtPostalCode.Text;
                    if (!string.IsNullOrEmpty(txtTelephone.Text))
                    {
                        data.telephone = Convert.ToInt64(txtTelephone.Text);
                    }
                     if (!string.IsNullOrEmpty(txtmobile.Text))
                     {
                        data.mobile = Convert.ToInt64(txtmobile.Text);
                     }
                    if (txtDOB.MaskFull)
                    {
                        data.DoB = Convert.ToDateTime(txtDOB.Text);
                    }
                    else
                    {
                        data.DoB = null;
                    }
                    if (txtBadExp.MaskFull)
                    {
                        data.badgeExpiry = Convert.ToDateTime(txtBadExp.Text);
                    }
                    else
                    {
                        data.badgeExpiry = null;
                    }

                    if (!string.IsNullOrEmpty(txtbadge.Text))
                    {
                        data.badgeID = Convert.ToInt32(txtbadge.Text);
                    }


                    data.radioSN = txtRadio.Text;
                    data.dataSN = txtVihtype.Text;
                    if (!string.IsNullOrEmpty(txtPinNo.Text))
                    {
                        data.pinNumber = Convert.ToInt32(txtPinNo.Text);
                    }
                    data.plate = txtPDA.Text;
                    if (!string.IsNullOrEmpty(txtComision.Text))
                    {
                        data.AcJobComm = Convert.ToInt32(txtComision.Text);
                    }
                    if (!string.IsNullOrEmpty(txtw_insure.Text))
                    {
                        data.weeklyInsurance = Convert.ToInt32(txtw_insure.Text);
                    }
                    if (!string.IsNullOrEmpty(txtWeekrent.Text))
                    {
                        data.weeklyRent = Convert.ToInt32(txtWeekrent.Text);
                    }
                    if (cmbSuspanded.Text == "Yes")
                    {
                        data.suspended = Convert.ToBoolean(1);
                    }
                    else
                    {
                        data.suspended = Convert.ToBoolean(0);
                    }

                    data.driverType = cmbDtype.Text;
                    data.picturePath = txtpathnew.Text;
                    data.picture = File.ReadAllBytes(txtpathnew.Text);
                    data.AccountAllocated = txtacallocated.Text;
                    data.AccountCommission = Convert.ToInt32(txtComision.Text);
                    data.weeklyInsurance = Convert.ToInt32(cmbweeklyInsurance.Text);
                    data.rentcoded = cmbrent.Text;
                    db.Drivers.Add(data);
                    db.SaveChanges();`
4

0 回答 0