تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
سؤال فى الحذف
#1
السلام عليكم

ازاى احذف اى بيان من كمبوبوكس 1 اذا كان مرتبط به كمبو بوكس 2 بمعنى ان اذا كان مثلا كمبو بوكس 1 به اسم احمد فيظهر فقط ابناء احمدفى كمبو2 فكيف احذف احمد من كمبوبوكس1 وبالتبعية تحذف ابناء احمد من كمبو2
الرد }}}
تم الشكر بواسطة: asemshahen5
#2
للاجابة على سؤالك يجب اولا معرفة اذا كان :
هل جميع البيانات في نفس الجدول ؟؟؟
وعل يتم تحميل كل الجدول في الفورم ؟
Don't Be The Perfect one
be the right one
الرد }}}
#3
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, "")


ده كود الاضافة ازاى اعمل منه كود حذف
الرد }}}
تم الشكر بواسطة: asemshahen5
#4
طبقا لأوامر الاضافة المذكورة فإنه يوجد لديك جدولين :
الاول : 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
الرد }}}
تم الشكر بواسطة: asemshahen5 , احمد خطاب , احمد خطاب
#5
الف مليون شكر
الرد }}}
تم الشكر بواسطة: asemshahen5



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم