دو جدول به نام پرسنل و جدول دیگه اردیبهشت برای ثبت کارکرد پرسنل دارم که کد پرسنلی رو در جدول اردیبهشت به عنوان کلید خارجی انتخاب کردم ولی موقه ای که می خوام اطلاعات رو ذخیره کنم. خطای
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Ordibeheshts_Persenel". The conflict occurred in database "E:\PROJECT ACCOUNTANCY\1397-02-02\ENTER\ENTER\BIN\DEBUG\DB\MARKET.MDF", table "dbo.Persenel", column 'id'.
The statement has been terminated.
رو می ده.با تشکر
چگونه ذخیره میکنید ؟
کد رو قرار بدید
کدش اینطوری
context = new DataenterDataContext();
Ordibehesht insert = new Ordibehesht();
insert.codep = Convert.ToInt32(txtcodepe.Text);
insert.name = txtname.Text;
insert.family = txtfamily.Text;
insert.hourse = Convert.ToInt32(txtHours.Text);
if (txtMonth.Text != "")
{
insert.karkardmoh = Convert.ToInt32(txtMonth.Text);
}
else
{
insert.karkardmoh = 0;
}
//
if (txtHoqoq.Text != "")
{
insert.hoqoqmahane = Convert.ToInt64(txtHoqoq.Text);
}
else
{
insert.hoqoqmahane = 0;
}
//
if (txtWether.Text != "")
{
insert.badwether = Convert.ToInt64(txtWether.Text);
}
else
{
insert.badwether = 0;
}
//
if (txtAyab.Text != "")
{
insert.ayab = Convert.ToInt64(txtAyab.Text);
}
else
{
insert.ayab = 0;
}
//
if (txtJazb.Text != "")
{
insert.haghjazb = Convert.ToInt64(txtJazb.Text);
}
else
{
insert.haghjazb = 0;
}
//
if (txtOlad.Text != "")
{
insert.olad = Convert.ToInt64(txtOlad.Text);
}
else
{
insert.olad = 0;
}
//
if (txtMaskan.Text != "")
{
insert.maskan = Convert.ToInt32(txtMaskan.Text);
}
else
{
insert.maskan = 0;
}
//
if (txtMamoriat.Text != "")
{
insert.mamoriat = Convert.ToInt64(txtMamoriat.Text);
}
else
{
insert.mamoriat = 0;
}
//
if (txtEidi.Text != "")
{
insert.eidee = Convert.ToInt64(txtEidi.Text);
}
else
{
insert.eidee = 0;
}
//
if (txtKharobar.Text != "")
{
insert.kharobar = Convert.ToInt64(txtKharobar.Text);
}
else
{
insert.kharobar = 0;
}
//
if (txtPadash.Text != "")
{
insert.padash = Convert.ToInt64(txtPadash.Text);
}
else
{
insert.padash = 0;
}
//
if (txtEzafekari.Text != "")
{
insert.ezafek = Convert.ToInt32(txtEzafekari.Text);
}
else
{
insert.ezafek = 0;
}
//
if (txtShabkari.Text != "")
{
insert.shabk = Convert.ToInt64(txtShabkari.Text);
}
else
{
insert.shabk = 0;
}
//
if (txtNobatkar.Text != "")
{
insert.nobatk = Convert.ToInt64(txtNobatkar.Text);
}
else
{
insert.nobatk = 0;
}
//
if (txtOtherM.Text != "")
{
insert.sayer = Convert.ToInt64(txtOtherM.Text);
}
else
{
insert.sayer = 0;
}
//
if (txtMosaede.Text != "")
{
insert.mosaede = Convert.ToInt64(txtMosaede.Text);
}
else
{
insert.mosaede = 0;
}
//
if (txtWam.Text != "")
{
insert.wam = Convert.ToInt32(txtWam.Text);
}
else
{
insert.wam = 0;
}
//
if (txtBime.Text != "")
{
insert.bkargar = Convert.ToInt64(txtBime.Text);
}
else
{
insert.bkargar = 0;
}
//
if (txtBimeKarfarma.Text != "")
{
insert.bkarfarma = Convert.ToInt64(txtBimeKarfarma.Text);
}
else
{
insert.bkarfarma = 0;
}
//
if (txtMHoqoq.Text != "")
{
insert.maliat = Convert.ToInt64(txtMHoqoq.Text);
}
else
{
insert.maliat = 0;
}
//
if (txtHoqoqMazaya.Text != "")
{
insert.jamehoqoqmazaya = Convert.ToInt64(txtHoqoqMazaya.Text);
}
else
{
insert.jamehoqoqmazaya = 0;
}
//
if (txtMashmoolBime.Text != "")
{
insert.mashmolb = Convert.ToInt32(txtMashmoolBime.Text);
}
else
{
insert.mashmolb = 0;
}
//
if (txtMMaliat.Text != "")
{
insert.mashmolmaliat = Convert.ToInt64(txtMMaliat.Text);
}
else
{
insert.mashmolmaliat = 0;
}
//
if (txtJameK.Text != "")
{
insert.jamekosorat = Convert.ToInt64(txtJameK.Text);
}
else
{
insert.jamekosorat = 0;
}
//
if (txtKhales.Text != "")
{
insert.khaleshoqoq = Convert.ToInt64(txtKhales.Text);
}
else
{
insert.khaleshoqoq = 0;
}
//
insert.tozihat = txtTozihat.Text;
//ذخیره تاریخ شمسی و میلادی
DateTime dtt = pct.ToDateTime(int.Parse(comyear.Text), int.Parse(commonth.Text), int.Parse(comday.Text), 0, 0, 0, 0, 0);
insert.Tarikh = pct.GetYear(dtt).ToString("0000") + "/" + pct.GetMonth(dtt).ToString("00") + "/" + pct.GetDayOfMonth(dtt).ToString("00");
insert.datemiladi = dtt;
context.Ordibeheshts.InsertOnSubmit(insert);
context.SubmitChanges();
dgvListP.DataSource = context.Ordibeheshts;
display();
ClearTextBoxes();
کد رو از طریق کلید کد ادیتور قرار دهید
try { context = new DataenterDataContext(); Ordibehesht insert = new Ordibehesht(); insert.codepid = Convert.ToInt32(txtcodepe.Text); insert.name = txtname.Text; insert.family = txtfamily.Text; insert.hourse = Convert.ToInt32(txtHours.Text); if (txtMonth.Text != "") { insert.karkardmoh = Convert.ToInt32(txtMonth.Text); } else { insert.karkardmoh = 0; } // if (txtHoqoq.Text != "") { insert.hoqoqmahane = Convert.ToInt64(txtHoqoq.Text); } else { insert.hoqoqmahane = 0; } // if (txtWether.Text != "") { insert.badwether = Convert.ToInt64(txtWether.Text); } else { insert.badwether = 0; } // if (txtAyab.Text != "") { insert.ayab = Convert.ToInt64(txtAyab.Text); } else { insert.ayab = 0; } // if (txtJazb.Text != "") { insert.haghjazb = Convert.ToInt64(txtJazb.Text); } else { insert.haghjazb = 0; } // if (txtOlad.Text != "") { insert.olad = Convert.ToInt64(txtOlad.Text); } else { insert.olad = 0; } // if (txtMaskan.Text != "") { insert.maskan = Convert.ToInt32(txtMaskan.Text); } else { insert.maskan = 0; } // if (txtMamoriat.Text != "") { insert.mamoriat = Convert.ToInt64(txtMamoriat.Text); } else { insert.mamoriat = 0; } // if (txtEidi.Text != "") { insert.eidee = Convert.ToInt64(txtEidi.Text); } else { insert.eidee = 0; } // if (txtKharobar.Text != "") { insert.kharobar = Convert.ToInt64(txtKharobar.Text); } else { insert.kharobar = 0; } // if (txtPadash.Text != "") { insert.padash = Convert.ToInt64(txtPadash.Text); } else { insert.padash = 0; } // if (txtEzafekari.Text != "") { insert.ezafek = Convert.ToInt32(txtEzafekari.Text); } else { insert.ezafek = 0; } // if (txtShabkari.Text != "") { insert.shabk = Convert.ToInt64(txtShabkari.Text); } else { insert.shabk = 0; } // if (txtNobatkar.Text != "") { insert.nobatk = Convert.ToInt64(txtNobatkar.Text); } else { insert.nobatk = 0; } // if (txtOtherM.Text != "") { insert.sayer = Convert.ToInt64(txtOtherM.Text); } else { insert.sayer = 0; } // if (txtMosaede.Text != "") { insert.mosaede = Convert.ToInt64(txtMosaede.Text); } else { insert.mosaede = 0; } // if (txtWam.Text != "") { insert.wam = Convert.ToInt32(txtWam.Text); } else { insert.wam = 0; } // if (txtBime.Text != "") { insert.bkargar = Convert.ToInt64(txtBime.Text); } else { insert.bkargar = 0; } // if (txtBimeKarfarma.Text != "") { insert.bkarfarma = Convert.ToInt64(txtBimeKarfarma.Text); } else { insert.bkarfarma = 0; } // if (txtMHoqoq.Text != "") { insert.maliat = Convert.ToInt64(txtMHoqoq.Text); } else { insert.maliat = 0; } // if (txtHoqoqMazaya.Text != "") { insert.jamehoqoqmazaya = Convert.ToInt64(txtHoqoqMazaya.Text); } else { insert.jamehoqoqmazaya = 0; } // if (txtMashmoolBime.Text != "") { insert.mashmolb = Convert.ToInt32(txtMashmoolBime.Text); } else { insert.mashmolb = 0; } // if (txtMMaliat.Text != "") { insert.mashmolmaliat = Convert.ToInt64(txtMMaliat.Text); } else { insert.mashmolmaliat = 0; } // if (txtJameK.Text != "") { insert.jamekosorat = Convert.ToInt64(txtJameK.Text); } else { insert.jamekosorat = 0; } // if (txtKhales.Text != "") { insert.khaleshoqoq = Convert.ToInt64(txtKhales.Text); } else { insert.khaleshoqoq = 0; } // insert.tozihat = txtTozihat.Text; //ذخیره تاریخ شمسی و میلادی DateTime dtt = pct.ToDateTime(int.Parse(comyear.Text), int.Parse(commonth.Text), int.Parse(comday.Text), 0, 0, 0, 0, 0); insert.Tarikh = pct.GetYear(dtt).ToString("0000") + "/" + pct.GetMonth(dtt).ToString("00") + "/" + pct.GetDayOfMonth(dtt).ToString("00"); insert.datemiladi = dtt; context.Ordibeheshts.InsertOnSubmit(insert); context.SubmitChanges(); dgvListP.DataSource = context.Ordibeheshts; display(); ClearTextBoxes();
به خدا من از این کدها سر در نمیارم
باید کدتون رو Trace کنید تا خطا رو بدست بیارید
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)