I am extremely new to programing and am trying to teach myself Visual Basic. I wrote a program that connects to an Access database. It successfully reads the table, however it will not update it. Can someone look at my code below and try to see what's wrong? Thanks.
Code:
Public Class frmCalls
'database declarations
Dim MyConnection As OleDbConnection
Dim callsCommand As OleDbCommand
Dim callsAdapter As OleDbDataAdapter
Dim callsTable As DataTable
Dim callsManager As CurrencyManager
'variable declarations
Dim maxrows As Integer
Dim inc As Integer
Dim countrows As Integer
Dim lowestdate As Integer
Dim testdate As Integer
Private Sub frmCalls_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'connect to books database
MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = c:\leads.mdb")
'open the connection
MyConnection.Open()
'establish command object
read = "select * " + "from " + Selection
callsCommand = New OleDbCommand(read, MyConnection)
'establish data adapter/data table
callsAdapter = New OleDbDataAdapter()
callsAdapter.SelectCommand = callsCommand
callsTable = New DataTable()
callsAdapter.Fill(callsTable)
'bind controls to data table
txtFirst.DataBindings.Add("Text", callsTable, "Borrower First Name")
txtLast.DataBindings.Add("Text", callsTable, "Borrower Last Name")
txtCofirst.DataBindings.Add("Text", callsTable, "Co-Borrower First Name")
txtColast.DataBindings.Add("Text", callsTable, "Co-borrower Last Name")
txtpropStreet.DataBindings.Add("Text", callsTable, "Property Address")
txtpropUnit.DataBindings.Add("Text", callsTable, "Property Unit")
txtpropCity.DataBindings.Add("Text", callsTable, "Property City")
txtpropState.DataBindings.Add("Text", callsTable, "Property State")
txtpropZip.DataBindings.Add("Text", callsTable, "Property Zip")
txtMailStreet.DataBindings.Add("Text", callsTable, "Mailing Address")
txtMailUnit.DataBindings.Add("Text", callsTable, "Mailing Unit")
txtMailCity.DataBindings.Add("Text", callsTable, "Mailing City")
txtMailState.DataBindings.Add("Text", callsTable, "Mailing State")
txtMailZip.DataBindings.Add("Text", callsTable, "Mailing Zip")
txthome.DataBindings.Add("Text", callsTable, "Home Phone")
txtwork.DataBindings.Add("Text", callsTable, "Work Phone")
txtCell.DataBindings.Add("Text", callsTable, "Cell Phone")
txtEmail.DataBindings.Add("Text", callsTable, "Email Address")
txtcurlender.DataBindings.Add("Text", callsTable, "Current Lender")
txtCuramount.DataBindings.Add("Text", callsTable, "Current Loan Amount")
txtCurRate.DataBindings.Add("Text", callsTable, "Current Rate")
txtCurPayment.DataBindings.Add("Text", callsTable, "Current Payment")
txtCurType.DataBindings.Add("Text", callsTable, "Current Rate Type")
txtCurDate.DataBindings.Add("Text", callsTable, "Current Origination Date")
txtBesttime.DataBindings.Add("Text", callsTable, "Best Time")
txtPurpose.DataBindings.Add("Text", callsTable, "Purpose of Loan")
txtLasttime.DataBindings.Add("Text", callsTable, "Last Call")
txtLastdisposition.DataBindings.Add("Text", callsTable, "Last Disposition")
txtLastlo.DataBindings.Add("Text", callsTable, "Last LO")
'establish currency manager
callsManager = DirectCast(Me.BindingContext(callsTable), CurrencyManager)
'find the oldest date
maxrows = callsTable.Rows.Count
countrows = 0
lowestdate = 0
testdate = 1
While countrows <> maxrows - 1
If (callsTable.Rows(lowestdate).Item(27) < callsTable.Rows(testdate).Item(27)) And (callsTable.Rows(lowestdate).Item(30).ToString = "0") And (callsTable.Rows(lowestdate).Item(31).ToString = "0") And (callsTable.Rows(lowestdate).Item(32).ToString = "0") Then
testdate = testdate + 1
countrows = countrows + 1
Else
If callsTable.Rows(testdate).Item(30) = 0 And callsTable.Rows(testdate).Item(31) = 0 And callsTable.Rows(testdate).Item(32) = 0 Then
lowestdate = testdate
testdate = testdate + 1
countrows = countrows + 1
Else
testdate = testdate + 1
countrows = countrows + 1
End If
End If
End While
callsManager.Position = lowestdate
'update last call time
callsAdapter.Update(callsTable)
'close the connection
MyConnection.Close()
'dispose of the connection object
MyConnection.Dispose()
callsCommand.Dispose()
callsAdapter.Dispose()
callsTable.Dispose()
End Sub