السلام عليكم ورحمة الله وبركاته وبعد :-
لدي كود استيراد بيانات موظفين من داتا قريد فيو إلى قاعدة بيانات sqlserver والذي أريده أن يتحقق من بيانات الموظفين قبل إرسالها إلى قاعدة بيانات هل هي موجودة أم لا حتى لا تتكرر في قاعدة البيانات مع العلم أنني وضعت حقل IdSijelMadni هو الحقل الذي لا تتكرر فيه البيانات (مفتاح أساسي)
وهذا هو الكود الذي استخدمه لإستيراد البيانات من الداتا قريد فيو إلى قاعدة البيانات
CmdServer.CommandType = CommandType.Text;
CmdServer.Connection = SqlConServer;
for (int ii = 0; ii < dataGridView1.Rows.Count - 1; ii++)
{
CmdServer.CommandText = "insert into TB_Techar ([IdSijelMadni],[NameFirst],[NameFather],[NameGrandFather],[NameFamely],[Job],[Takss],[Mobile],,[IdSchoolWazara]) values('" + dataGridView1.Rows[ii].Cells[0].Value + "','" + dataGridView1.Rows[ii].Cells[1].Value + "','" + dataGridView1.Rows[ii].Cells[2].Value + "','" + dataGridView1.Rows[ii].Cells[3].Value + "','" + dataGridView1.Rows[ii].Cells[4].Value + "','" + dataGridView1.Rows[ii].Cells[5].Value + "','" + dataGridView1.Rows[ii].Cells[6].Value + "','" + dataGridView1.Rows[ii].Cells[7].Value + "','" + dataGridView1.Rows[ii].Cells[8].Value + "','" + dataGridView1.Rows[ii].Cells[9].Value + "') ";
SqlConServer.Open();
CmdServer.ExecuteNonQuery();
SqlConServer.Close();
}
MessageBox.Show("تم الحفظ بنجاح", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Information);
}