السلام عليكم
هل هناك من طريقة سهلة لإتمام حذف الصفوف في جدول الابن عند حذف صف من الجدول الأب ، وجدت أكثر من طريقة ولكن لم افهمها بشكل كامل :) والمعذرة لأني مبتدئ في فحول بيسك وآمل شرحها لعلي افهم أو اجد لديكم طريقة أسهل وشكرا
هذه طريقة اعتقد أنها تنفع مع تفعيل خاصية تتالي الحذف
والشرح مفهوم ما عدى الكود التالي
Imports System.Data.SqlServerCe
Public Class SQLCEIDHelper
''' <summary>
''' Retrieves the primary key auto-number identity values from SQL CE
''' </summary>
''' <remarks></remarks>
Public Shared Sub SetPrimaryKey(ByVal trans As SqlCeTransaction, _
ByVal e As SqlCeRowUpdatedEventArgs)
' If this is an INSERT operation...
If e.Status = UpdateStatus.Continue AndAlso _
e.StatementType = StatementType.Insert Then
Dim pk = e.Row.Table.PrimaryKey
' and a primary key PK column exists...
If pk IsNot Nothing AndAlso pk.Count = 1 Then
'Set up the post-update query to fetch new @@Identity
Dim cmdGetIdentity As New SqlCeCommand("SELECT @@IDENTITY", _
CType(trans.Connection, SqlCeConnection), _
trans)
'Execute the command and set the result identity value to the PK
e.Row(pk(0)) = CInt(cmdGetIdentity.ExecuteScalar)
e.Row.AcceptChanges()
End If
End If
End Sub
End Class
Namespace MyDatabaseDataSetTableAdapters
Partial Public Class CategoriesTableAdapter
Private Sub _adapter_RowUpdated(ByVal sender As Object, _
ByVal e As SqlCeRowUpdatedEventArgs) _
Handles _adapter.RowUpdated
SQLCEIDHelper.SetPrimaryKey(Me.Transaction, e)
End Sub
End Class
Partial Public Class ProductsTableAdapter
Private Sub _adapter_RowUpdated(ByVal sender As Object, _
ByVal e As SqlCeRowUpdatedEventArgs) _
Handles _adapter.RowUpdated
SQLCEIDHelper.SetPrimaryKey(Me.Transaction, e)
End Sub
End Class
End Namespace
Partial Class MyDatabaseDataSet
Partial Class CategoriesDataTable
Private Sub CategoriesDataTable_TableNewRow(ByVal sender As Object, _
ByVal e As System.Data.DataTableNewRowEventArgs) _
Handles Me.TableNewRow
'Set defaults so that constraints don't fail when EndEdit is called
Dim cat = CType(e.Row, CategoriesRow)
cat.CategoryName = "[new]"
End Sub
End Class
Partial Class ProductsDataTable
Private Sub ProductsDataTable_TableNewRow(ByVal sender As Object, _
ByVal e As System.Data.DataTableNewRowEventArgs) _
Handles Me.TableNewRow
'Set defaults so that constraints don't fail when EndEdit is called
Dim product = CType(e.Row, ProductsRow)
product.ProductName = "[new]"
End Sub
End Class
End Class
][/codImports System.Data.SqlServerCe
Public Class SQLCEIDHelper
''' <summary>
''' Retrieves the primary key auto-number identity values from SQL CE
''' </summary>
''' <remarks></remarks>
Public Shared Sub SetPrimaryKey(ByVal trans As SqlCeTransaction, _
ByVal e As SqlCeRowUpdatedEventArgs)
' If this is an INSERT operation...
If e.Status = UpdateStatus.Continue AndAlso _
e.StatementType = StatementType.Insert Then
Dim pk = e.Row.Table.PrimaryKey
' and a primary key PK column exists...
If pk IsNot Nothing AndAlso pk.Count = 1 Then
'Set up the post-update query to fetch new @@Identity
Dim cmdGetIdentity As New SqlCeCommand("SELECT @@IDENTITY", _
CType(trans.Connection, SqlCeConnection), _
trans)
'Execute the command and set the result identity value to the PK
e.Row(pk(0)) = CInt(cmdGetIdentity.ExecuteScalar)
e.Row.AcceptChanges()
End If
End If
End Sub
End Class
Namespace MyDatabaseDataSetTableAdapters
Partial Public Class CategoriesTableAdapter
Private Sub _adapter_RowUpdated(ByVal sender As Object, _
ByVal e As SqlCeRowUpdatedEventArgs) _
Handles _adapter.RowUpdated
SQLCEIDHelper.SetPrimaryKey(Me.Transaction, e)
End Sub
End Class
Partial Public Class ProductsTableAdapter
Private Sub _adapter_RowUpdated(ByVal sender As Object, _
ByVal e As SqlCeRowUpdatedEventArgs) _
Handles _adapter.RowUpdated
SQLCEIDHelper.SetPrimaryKey(Me.Transaction, e)
End Sub
End Class
End Namespace
Partial Class MyDatabaseDataSet
Partial Class CategoriesDataTable
Private Sub CategoriesDataTable_TableNewRow(ByVal sender As Object, _
ByVal e As System.Data.DataTableNewRowEventArgs) _
Handles Me.TableNewRow
'Set defaults so that constraints don't fail when EndEdit is called
Dim cat = CType(e.Row, CategoriesRow)
cat.CategoryName = "[new]"
End Sub
End Class
Partial Class ProductsDataTable
Private Sub ProductsDataTable_TableNewRow(ByVal sender As Object, _
ByVal e As System.Data.DataTableNewRowEventArgs) _
Handles Me.TableNewRow
'Set defaults so that constraints don't fail when EndEdit is called
Dim product = CType(e.Row, ProductsRow)
product.ProductName = "[new]"
End Sub
End Class
End Classالحل الثاني ذكره مشرف في المنتدى بس ما فهمته أبدا على هذا الرابط
آمل شرح فكرة remove at
وشكرا لكم