25-09-17, 05:49 AM
25-09-17, 03:46 PM
تفضل اخي
كود :
Private Sub fill_combobox_grid()
Try
'فحص الاتصال بقاعدة البيانات
If SQL.conn.State = ConnectionState.Open Then
SQL.conn.Close()
End If
SQL.conn.Open()
Dim cmd As New SqlCommand()
cmd.Connection = SQL.conn
cmd.CommandText = "select DISTINCT con_id from contracts where cust_id=@cust_id"
cmd.Parameters.AddWithValue("@cust_id", DataGrid_monthly.SelectedRows(0).Cells(3).Value)
Dim dr As SqlDataReader = cmd.ExecuteReader
While dr.Read
Dim esection As String = dr.Item(0)
End While
combobox1.Items.add(esection )
dr.Close()
SQL.conn.Close()
Catch ex As SqlException
MsgBox(ex.Message, MsgBoxStyle.Critical, "SQL Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub25-09-17, 04:07 PM
كود :
Dim da As New OleDbDataAdapter("SELECT * FROM Table1", con)
Dim dt As DataTable
da.Fill(dt)
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "name"
ComboBox1.ValueMember = "id"