We connect to a database using a sub (RUNCMD) which we created.
It takes 2 parameters a string which is executed and a delegate function
of this type:
Expand|Select|Wrap|Line Numbers
- Delegate Function OutputDataReader(ByRef dr As SqlDataReader) As Boolean
- Public Overloads Function RunCMD(ByVal sSQLSTR As String, ByVal datafetch As OutputDataReader) As Boolean
- This is how we use it:
- Public Function LoadAffordabilityPercentsFromConnection() As Boolean
- Try
- If Not mvar_DataFetched Then
- If Not DS.RunCMD("EXEC Get_df_AffordabilityPercents", AddressOf LoadAffordabilityPercents) Then
- MsgBox("Problem fetching Affordability Percents!", MsgBoxStyle.Critical, "Object Build failure")
- Exit Function
- End If
- End If
- Catch ex As Exception
- Throw New Exception("LoadAffordabilityPercentsFromConnection had an error " + ex.Message)
- End Try
- End Function Public Function LoadAffordabilityPercents(ByRef dr As SqlDataReader) As Boolean
- Try
- If dr.Read Then
- BasicSalaryPerc = CStr(dr.GetValue(0))
- OverTimePerc = CStr(dr.GetValue(1))
- RecurringAllowancesConfirmedPerc = CStr(dr.GetValue(2))
- NonRecurringAllowancesPerc = CStr(dr.GetValue(3))
- CommissionPerc = CStr(dr.GetValue(4))
- OtherIncomePerc = CStr(dr.GetValue(5))
- IncomeTaxPerc = CStr(dr.GetValue(6))
- PaySlipLoanRepaymentsPerc = CStr(dr.GetValue(7))
- PaySlipOtherDeductionsPerc = CStr(dr.GetValue(8))
- CommitmentsNLRPerc = CStr(dr.GetValue(9))
- CommitmentsCCAPerc = CStr(dr.GetValue(10))
- LivingExpensesPerc = CStr(dr.GetValue(11))
- MaintenancePerc = CStr(dr.GetValue(12))
- MunicipalServicesPerc = CStr(dr.GetValue(13))
- OtherIncomeNotOnPaySlipPerc = CStr(dr.GetValue(14))
- DisplayPercents = CBool(dr.GetValue(15))
- RentPerc = CStr(dr.GetValue(16))
- MedicalPerc = CStr(dr.GetValue(17))
- WaterAndLightsPerc = CStr(dr.GetValue(18))
- EducationPerc = CStr(dr.GetValue(19))
- SavingsPerc = CStr(dr.GetValue(20))
- InsurancePerc = CStr(dr.GetValue(21))
- TransportPerc = CStr(dr.GetValue(22))
- PensionAndSavingsPerc = CStr(dr.GetValue(23))
- ActiveDebtCommitmentsPerc = CStr(dr.GetValue(24))
- OtherDeductionsNotOnPaySlipPerc = CStr(dr.GetValue(25))
- minLivingExpenses = CStr(dr.GetValue(26))
- mvar_DataFetched = True
- End If
- Return True
- Catch ex As Exception
- Throw New Exception("LoadAffordabilityPercents had an error " + ex.Message)
- Return False
- End Try
- End Function