I am new to the .NET environment and coming from
VB 6. I am now using
VB 2013 and am having a hard time transitioning. I am trying to read two tables (ASB_Formula_Info) and (AnnualSupplementalExtract). After various calculations, I need to update the AnnualSupplementalExtract table with the results from the calculation. I have searched the internet on how to go about doing this and have applied what I think how it is done. Seems like I am doing something wrong since the table is not getting updated.
Please help me if I am missing something on my code. I have tried several ways and I am not able to get the table AnnualSupplementalExtract to update. I have checked if the records are being read and calculated and I see that they are.
Code:
Public Class Form1
Dim MDBConnString AsString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\MyPath\ASB.mdb"
Dim strTableName AsString
Dim sqlString AsString
Dim intASBYear AsInteger
Dim cnn As OleDb.OleDbConnection
Dim cmd As OleDb.OleDbCommand
Dim daInfo As OleDb.OleDbDataAdapter
Dim daASBExtract As OleDb.OleDbDataAdapter
PrivateSub btnStart_Click(sender AsObject, e AsEventArgs) Handles btnStart.Click
strTableName = "ASB_Formula_Info"
sqlString = "SELECT * FROM " & strTableName & " WHERE ASB_Year = (" & dtpPricing.Value.Year & " - 1)"
cnn = New OleDb.OleDbConnection(MDBConnString)
cnn.Open()
cmd = New OleDb.OleDbCommand(sqlString, cnn)
daInfo = New OleDb.OleDbDataAdapter(cmd)
Dim dsASB AsNewDataSet("ASB")
daInfo.Fill(dsASB, strTableName)
Dim tblInfo AsDataTable
tblInfo = dsASB.Tables(strTableName)
Dim drCurrent AsDataRow
intASBYear = tblInfo.Rows(0).Item("ASB_Year")
txtActualBenefitAllocation.Text = intASBYear
strTableName = "AnnualSupplementalExtract"
sqlString = "SELECT * FROM " & strTableName
'Dim dsASBExtract As New DataSet
cnn = New OleDb.OleDbConnection(MDBConnString)
cnn.Open()
cmd = New OleDb.OleDbCommand(sqlString, cnn)
daASBExtract = New OleDb.OleDbDataAdapter(cmd)
daASBExtract.Fill(dsASB, strTableName)
Dim tblASBExtract AsDataTable
tblASBExtract = dsASB.Tables(strTableName)
' Compute Total Years Since Retirement
Dim dblTotalAge AsDouble
For i AsInteger = 0 To tblASBExtract.Rows.Count - 1
If IsNumeric(tblASBExtract.Rows(i).Item("Years Since Retirement")) Then
dblTotalAge = Math.Round(dblTotalAge + tblASBExtract.Rows(i).Item("Years Since Retirement"), 2)
EndIf
Next
' Compute percentage of allocation
Dim dblAllocation AsDouble
' For i As Integer = 0 To tblASBExtract.Rows.Count - 1
'On Error Resume Next
'With tblASBExtract.Rows(i)
' dblAllocation = Math.Round((tblASBExtract.Rows(i).Item("Years Since Retirement") / dblTotalAge), 8)
' .Item("Allocation") = dblAllocation
'.Item("Benefit Based on Retirement Date") = Math.Round((dblAllocation * tblInfo.Rows(0).Item("ASB_Total_Benefit_Allocation")), 2)
'daASBExtract.Update(dsASB, strTableName)
'End With
'Next
For i AsInteger = 0 To tblASBExtract.Rows.Count - 1
OnErrorResumeNext
drCurrent = tblASBExtract.Rows(i)
If IsNumeric(drCurrent("Years Since Retirement")) Then
dblAllocation = Math.Round((drCurrent("Years Since Retirement") / dblTotalAge), 8)
drCurrent.BeginEdit()
drCurrent("Allocation") = CDbl(Math.Round((drCurrent("Years Since Retirement") / dblTotalAge), 8))
drCurrent("Benefit Based on Retirement Date") = CDbl(Math.Round((drCurrent("Allocation") * tblInfo.Rows(0).Item("ASB_Total_Benefit_Allocation")), 2))
drCurrent.EndEdit()
daASBExtract.Update(dsASB, "AnnualSupplementalExtract")
EndIf
Next
cnn.Close()
txtPovertyLevel.Text = dblTotalAge
EndSub
Thanks