29-12-19, 01:04 PM
(آخر تعديل لهذه المشاركة : 29-12-19, 01:10 PM {2} بواسطة asemshahen5.)
ضع هذا الكود في مديول :
ضع هذا في حدث تحميل الفورم :
PHP كود :
'ضع هذا الكود في مديول'
Public Sub FillComboBoxXT(ComboName As ComboBox, TableName As String, ColumnName As String)
Dim StrSQL As String = "Select DISTINCT " & ColumnName & " From " & TableName
Dim dt As New DataTable
dt = FillDataTableXT(StrSQL)
If dt Is Nothing Then
dt = FillDataTableXT(StrSQL)
End If
If dt Is Nothing Then
Exit Sub
End If
ComboName.DataSource = Nothing
ComboName.DataSource = dt
ComboName.DisplayMember = ColumnName
End Sub
'ضع هذا الكود في مديول'
Public CnnStringXT As String = "Data Source=(Local);Initial Catalog=DatabaseNameXT;Integrated Security=True"
'ضع هذا الكود في مديول'
Public CnnXT As New SqlConnection(CnnStringXT)
'ضع هذا الكود في مديول'
Public Function FillDataTableXT(StrSQL As String) As DataTable
Dim dt As New DataTable
Try
CnnXT = New SqlConnection(CnnStringXT)
If CnnXT.State = ConnectionState.Closed Then CnnXT.Open()
Dim da As New SqlDataAdapter(StrSQL, CnnXT)
dt.Clear()
da.Fill(dt)
If CnnXT.State = ConnectionState.Open Then CnnXT.Close()
If dt Is Nothing Then
dt = FillDataTableXT(StrSQL)
End If
If dt Is Nothing Then
dt = FillDataTableXT(StrSQL)
If dt Is Nothing Then
Return Nothing
Exit Function
End If
End If
Return dt
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error :" & ex.HelpLink)
Return FillDataTableXT(StrSQL)
End Try
End Function
ضع هذا في حدث تحميل الفورم :
PHP كود :
FillComboBoxXT(ComboBox1, "TableName", "ColumnName")
سبحان الله وبحمده سبحان الله العظيم و الحمد لله ولا اله الا الله والله اكبر
