تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تعبئة CheckListBox من قاعدة البيانات حسب الإختيار من Combobox
#1
السلام عليكم ورحمة الله وبركاته 

هل أستطيع عرض كافة حقول جدول من قاعدة البيانات Sql إلى CheckListBox  بإستخدام كومبوبوكس بحيث يعرض حسب القيمة المحددة في الكومبوبوكس 
بارك الله فيكم
الرد }}}
تم الشكر بواسطة:
#2
كود :
Imports System.Data.SqlClient

Public Class Form1
   ' Your database connection string
   Dim connectionString As String = "YourConnectionStringHere"

   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       ' Populate the ComboBox with data on form load
       PopulateComboBox()
   End Sub

   Private Sub PopulateComboBox()
       ' Your SQL query to retrieve distinct values for the ComboBox
       Dim query As String = "SELECT DISTINCT YourColumnName FROM YourTableName"
       
       ' Create a SqlConnection
       Using connection As New SqlConnection(connectionString)
           ' Open the connection
           connection.Open()

           ' Create a SqlCommand
           Using command As New SqlCommand(query, connection)
               ' Create a SqlDataReader to read data
               Using reader As SqlDataReader = command.ExecuteReader()
                   ' Clear existing items in the ComboBox
                   comboBox1.Items.Clear()

                   ' Add items to the ComboBox
                   While reader.Read()
                       comboBox1.Items.Add(reader("YourColumnName").ToString())
                   End While
               End Using
           End Using
       End Using
   End Sub

   Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comboBox1.SelectedIndexChanged
       ' Clear existing items in the CheckBoxList
       checkBoxList1.Items.Clear()

       ' Check if an item is selected in the ComboBox
       If comboBox1.SelectedItem IsNot Nothing Then
           ' Get the selected value from the ComboBox
           Dim selectedValue As String = comboBox1.SelectedItem.ToString()

           ' Call a method to populate the CheckBoxList based on the selected value
           PopulateCheckBoxList(selectedValue)
       End If
   End Sub

   Private Sub PopulateCheckBoxList(selectedValue As String)
       ' Your SQL query to retrieve values for the CheckBoxList based on the selected value
       Dim query As String = "SELECT YourCheckBoxListColumnName FROM YourTableName WHERE YourComboBoxColumnName = @SelectedValue"

       ' Create a SqlConnection
       Using connection As New SqlConnection(connectionString)
           ' Open the connection
           connection.Open()

           ' Create a SqlCommand with parameters
           Using command As New SqlCommand(query, connection)
               ' Add parameters
               command.Parameters.AddWithValue("@SelectedValue", selectedValue)

               ' Create a SqlDataReader to read data
               Using reader As SqlDataReader = command.ExecuteReader()
                   ' Add items to the CheckBoxList
                   While reader.Read()
                       checkBoxList1.Items.Add(reader("YourCheckBoxListColumnName").ToString())
                   End While
               End Using
           End Using
       End Using
   End Sub
End Class
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  اختصار كود الجمع داخل شبكة البيانات محمد خيري 2 157 25-04-24, 03:30 PM
آخر رد: محمد خيري
  كيف اتعامل مع databindings و ال combobox سلام و محبه 2 115 24-03-24, 05:00 AM
آخر رد: سلام و محبه
  هل من الممكن العمل على قاعدة بيانات اكسل على الفيجوال بيسك خالد كامل1 4 194 24-03-24, 02:00 AM
آخر رد: خالد كامل1
  [VB.NET] حل مشكلة الاتصال بقواعد البيانات access loay775 2 230 25-02-24, 06:29 AM
آخر رد: loay775
  انشاء قاعدة بيانات من ملف سكربت strongriseman 5 541 17-02-24, 02:57 PM
آخر رد: strongriseman
  سؤال عن عملية حذف سجل من قاعدة البيانات assuhimi 3 295 11-02-24, 08:43 PM
آخر رد: assuhimi
  فلترة datagridview بدون قاعدة بيانات صالح عبدالله 3 363 02-02-24, 04:07 PM
آخر رد: صالح عبدالله
  [VB.NET] منع تكرار البيانات في عند الادخال مبرمج صغير 1 2 345 24-01-24, 05:18 PM
آخر رد: مبرمج صغير 1
Photo [كود] مطلوب كود يستخدم الأوامر فقط لتحديث قاعدة بيانات بـ vb.net AhmedEissa 4 677 18-01-24, 11:40 PM
آخر رد: العتيق
  [VB.NET] استدعاء بيانات في TextBox بناء على combobox loay775 2 316 18-01-24, 05:07 PM
آخر رد: loay775

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


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