وعليكم السلام ورحمة الله وبركاته
المثال الذي طرحه الأخ (IYC) مميز ومرتب،،
ولكن إن كنت لا تحبين الربط بين الجداول ضمن قاعدة البيانات والاعتماد فقط على الأكواد في الادخال والربط :
فاستخدمي الكود التالي بدلاً من الكود الموجود في مثالك ..
بنفس الطريقة التي طرحتها ولكن بشكل أبسط وأسلس ..
كود :
If MsgBox("هل تريد حفظ بيانات هذا السجل فعلا ؟", MessageBoxButtons.YesNo + MsgBoxStyle.DefaultButton2 + MessageBoxIcon.Question + MsgBoxStyle.MsgBoxRight, "حفظ البيانات") = vbNo Then Exit Sub
' التأكد من تعبئة كل الحقول
If txtmynumber.Text = "" Then
MsgBox("اكتب رقم المعاملة ", MessageBoxButtons.OK + MsgBoxStyle.DefaultButton1 + MessageBoxIcon.Exclamation + MsgBoxStyle.MsgBoxRight, "رقم المعاملة") : txtmynumber.Select() : Exit Sub
ElseIf TextBox1.Text = "" Then
MsgBox("اكتب الرقم الوظيفي ", MessageBoxButtons.OK + MsgBoxStyle.DefaultButton1 + MessageBoxIcon.Exclamation + MsgBoxStyle.MsgBoxRight, "الرقم الوظيفي") : TextBox1.Select() : Exit Sub
ElseIf TextBox2.Text = "" Then
MsgBox("اكتب اسم الموظف ", MessageBoxButtons.OK + MsgBoxStyle.DefaultButton1 + MessageBoxIcon.Exclamation + MsgBoxStyle.MsgBoxRight, "اسم الموظف") : TextBox2.Select() : Exit Sub
ElseIf TextBox6.Text = "" Then
MsgBox("اكتب نوع العطل ", MessageBoxButtons.OK + MsgBoxStyle.DefaultButton1 + MessageBoxIcon.Exclamation + MsgBoxStyle.MsgBoxRight, "نوع العطل ") : TextBox6.Select() : Exit Sub
ElseIf TextBox4.Text = "" Then
MsgBox("اكتب وصف العطل ", MessageBoxButtons.OK + MsgBoxStyle.DefaultButton1 + MessageBoxIcon.Exclamation + MsgBoxStyle.MsgBoxRight, "اكتب وصف للعطل ") : TextBox4.Select() : Exit Sub
ElseIf TextBox5.Text = "" Then
MsgBox("اكتب تقرير الفني ", MessageBoxButtons.OK + MsgBoxStyle.DefaultButton1 + MessageBoxIcon.Exclamation + MsgBoxStyle.MsgBoxRight, "تقرير الفني ") : TextBox5.Select() : Exit Sub
ElseIf TextBox3.Text = "" Then
MsgBox("اكتب تقرير المسؤل المباشر ", MessageBoxButtons.OK + MsgBoxStyle.DefaultButton1 + MessageBoxIcon.Exclamation + MsgBoxStyle.MsgBoxRight, "تقرير المسئول المباشر ") : TextBox3.Select() : Exit Sub
End If
Dim CmdInsert As New OleDbCommand
CmdInsert.Connection = Con
'========================================================================
Dim A1 As DateTime = DateTimePicker1.Text.Trim
Dim A2 As String = cmpDepartment.Text.Trim
Dim A3 As Int16 = TextBox1.Text.Trim
Dim A4 As String = TextBox2.Text.Trim
Dim A5 As Int16 = txtmynumber.Text.Trim
Dim A6 As String = cmpSection.Text.Trim
Dim A7 As String = TextBox6.Text.Trim
Dim A8 As String = TextBox4.Text.Trim
Dim A9 As String = TextBox5.Text.Trim
Dim A10 As String = TextBox3.Text.Trim
CmdInsert.CommandText = $" Insert Into maintanice (Damage_Date,
MyDepertment, Emp_ID, Emp_Name, tNumber ,
MySection, Damage_Type, Damage_Des,
tecnical_Report, Headsection_Report ) values
( #{A1}# ,'{A2}', {A3}, '{A4}', '{A5}' ,
'{A6}' ,'{A7}', '{A8}', '{A9}', '{A10}' ) "
If Con.State = ConnectionState.Open Then Con.Close()
Con.Open()
CmdInsert.ExecuteNonQuery()
Con.Close()
'===================================================================
MsgBox(" تم إضافة البيانات بنجاح ", MsgBoxStyle.Information, "إضافة")
CmdInsert = Nothing
المتغيرات التي أفترضتها A1..A2 ...... إلخ
بإمكانك تغييرها لأسماء تناسب البيانات المخزنة فيها
ولكن من أجل السرعة افترضت هذه الاسماء لها ...