المشاركات : 195
المواضيع 87
الإنتساب : Oct 2018
السمعة :
0
الشكر: 81
تم شكره 100 مرات في 68 مشاركات
السلام عليكم
ازاى احذف اى بيان من كمبوبوكس 1 اذا كان مرتبط به كمبو بوكس 2 بمعنى ان اذا كان مثلا كمبو بوكس 1 به اسم احمد فيظهر فقط ابناء احمدفى كمبو2 فكيف احذف احمد من كمبوبوكس1 وبالتبعية تحذف ابناء احمد من كمبو2
المشاركات : 505
المواضيع 8
الإنتساب : Sep 2015
السمعة :
38
الشكر: 92
تم شكره 1402 مرات في 345 مشاركات
للاجابة على سؤالك يجب اولا معرفة اذا كان :
هل جميع البيانات في نفس الجدول ؟؟؟
وعل يتم تحميل كل الجدول في الفورم ؟
Don't Be The Perfect one
be the right one
المشاركات : 195
المواضيع 87
الإنتساب : Oct 2018
السمعة :
0
الشكر: 81
تم شكره 100 مرات في 68 مشاركات
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text.Trim = "" Or TextBox2.Text.Trim = "" Then Exit Sub
Button1.Enabled = False
Using con As New OleDb.OleDbConnection(str)
Using cm As New OleDb.OleDbCommand("", con)
cm.CommandText = "insert into country (countryname) values(@countryname)"
cm.Parameters.AddWithValue("@countryname", TextBox1.Text)
If con.State = ConnectionState.Closed Then con.Open()
cm.ExecuteNonQuery()
cm.Parameters.Clear()
'انتبه اجعل الاتصال مفتوح لتحصل على آخر رقم اي دي
cm.CommandText = "select@@identity"
Dim id As Integer
If con.State = ConnectionState.Closed Then con.Open()
id = cm.ExecuteScalar
If con.State = ConnectionState.Open Then con.Close()
cm.Parameters.Clear()
If con.State = ConnectionState.Closed Then con.Open()
For Each h As String In TextBox2.Text.Split(vbNewLine)
cm.Parameters.Clear()
cm.CommandText = "insert into city (countryid,cityname) values(@countryid,@cityname)"
cm.Parameters.AddWithValue("@countryid", id)
cm.Parameters.AddWithValue("@cityname", h)
cm.ExecuteNonQuery()
Next
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
gd()
Button1.Enabled = True
MsgBox("تم حفظ الدولة ومدنها", MsgBoxStyle.Information, "")
ده كود الاضافة ازاى اعمل منه كود حذف
المشاركات : 505
المواضيع 8
الإنتساب : Sep 2015
السمعة :
38
الشكر: 92
تم شكره 1402 مرات في 345 مشاركات
26-12-19, 02:40 AM
(آخر تعديل لهذه المشاركة : 26-12-19, 02:41 AM {2} بواسطة boudyonline.)
طبقا لأوامر الاضافة المذكورة فإنه يوجد لديك جدولين :
الاول : Country
والثاني : City
وعلى ذلك يتم اولا حذف المدن من الجدول City التي لها كود الدولة المطلوب حذفها
Delete from city where countryid = @countryid
ثم من الجدول Country يتم حذف الدولة المراد حذفها طبقا للإمر السابق
Delete from country where countryid = @countryid
Don't Be The Perfect one
be the right one