02-10-18, 09:50 PM
أهلاً أخي
أعذر الجميع أكيد مشغولين .
الخطاء عندك في إستخدام هذا السطر
Dim CTL As New Control
هذا الكود بعد التعديل :
لا تنسى إضافة هذا الـ Module في ملف آخر أو في أسفل وخارج الـ Class الخاص بالـ Form :
وظيفتة يرجع جميع عناصر التحكم ( الـ Controls ) الموجودة في النافذة , ( بالطريقة التي إستخدمتها أنت لن يتم إرجاع إلا الـ TopLevel أبناء النافذة فقط , وأي أبناء لعنصر مختلف مثل الـ Panel لن يتم إرجاعهم )
جرب وأخبرني لأني لا أستطيع إختبار الكود .
أعذر الجميع أكيد مشغولين .
الخطاء عندك في إستخدام هذا السطر
Dim CTL As New Control
هذا الكود بعد التعديل :
كود :
Try
Dim sql = ("select * from Company_Details where Company_ID=N'" & (Company_ID.Text) & "'")
Dim adp As New SqlClient.SqlDataAdapter(sql, sqlconn)
Dim ds As New DataSet
adp.Fill(ds)
Dim dt = ds.Tables(0)
If dt.Rows.Count > 0 Then
Exit Sub
Else
Dim dr = dt.NewRow
'----------------------------------------------------------------------------------------
For Each Ctrl In Me.FindAllChildren
If TypeOf Ctrl Is TextBox And dt.Columns.Contains(Ctrl.Name) Then
dr.Item(Ctrl.Name) = Ctrl.Text
End If
Next
'----------------------------------------------------------------------------------------
dt.Rows.Add(dr)
'Dim cmd As New SqlClient.SqlCommandBuilder(adp)
adp.Update(dt)
MsgBox("تم حفظ بيانات الشركة بنجاح", MsgBoxStyle.Information, "رسالة تأكيد ")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "فشل في عملية الحفظ ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
End Tryلا تنسى إضافة هذا الـ Module في ملف آخر أو في أسفل وخارج الـ Class الخاص بالـ Form :
وظيفتة يرجع جميع عناصر التحكم ( الـ Controls ) الموجودة في النافذة , ( بالطريقة التي إستخدمتها أنت لن يتم إرجاع إلا الـ TopLevel أبناء النافذة فقط , وأي أبناء لعنصر مختلف مثل الـ Panel لن يتم إرجاعهم )
كود :
Public Module ExtensionModule
<Runtime.CompilerServices.Extension()>
Public Function FindAllChildren(ByRef StartingContainer As System.Windows.Forms.Control) As List(Of System.Windows.Forms.Control)
Dim Children As New List(Of System.Windows.Forms.Control)
If StartingContainer.HasChildren = False Then
Return Nothing
Else
Dim oControl As System.Windows.Forms.Control
For Each oControl In StartingContainer.Controls
Children.Add(oControl)
If oControl.HasChildren Then
Children.AddRange(oControl.FindAllChildren())
End If
Next
End If
Return Children
End Function
End Moduleجرب وأخبرني لأني لا أستطيع إختبار الكود .
