1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| 'Déclaration de variable global
Private _dtFreightRate As New DataTable
Private _dsFreightRate As New DataSet
'appel de la fonction
Private Sub cboCarrier_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCarrier.TextChanged
findCarrier(Me.cboCompany.Text, Me.cboDivision.Text, Me.cboCarrier.Text)
End Sub
'Fonction
Private Function findCarrier(ByVal strCompany As String, ByVal strDivision As String, ByVal strCarrier As String) As DataTable
Dim strSql As String
Dim sqlConnectionCrps As SqlConnection
Dim sqlCommandCrps As SqlCommand
Dim sqlDataAdapterCrps As SqlDataAdapter
Try
sqlConnectionCrps = New SqlConnection
sqlConnectionCrps.ConnectionString = CONNECTION_STRING
sqlConnectionCrps.Open()
strSql = "SELECT company_code, " + _
" division, " + _
" vendor_number, " + _
" location_code_from, " + _
" location_code_to, " + _
" rate_type, " + _
" charge_category_code, " + _
" rate, " + _
" rate_basis_unit, " + _
" currency_code, " + _
" date_effective_from, " + _
" date_effective_to " + _
"FROM freight_rate " + _
"WHERE company_code = '" & Me.cboCompany.Text & "' " + _
"AND division = '" & Me.cboDivision.Text & "' " + _
"AND vendor_number = '" & Me.cboCarrier.Text & "' "
sqlCommandCrps = sqlConnectionCrps.CreateCommand
sqlCommandCrps.CommandText = strSql
sqlDataAdapterCrps = New SqlDataAdapter(sqlCommandCrps)
sqlCommandCrps.Connection = sqlConnectionCrps
_dsFreightRate.Clear()
sqlDataAdapterCrps.Fill(_dsFreightRate, "freight_rate")
_dtFreightRate.Clear()
_dtFreightRate = _dsFreightRate.Tables("freight_rate")
Return _dtFreightRate
Catch ex As Exception
Throw New Exception("findCarrier() : " + ex.Message)
Finally
sqlConnectionCrps = Nothing
sqlCommandCrps = Nothing
sqlDataAdapterCrps = Nothing
End Try
End Function |
Partager