By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Why Won't My Database Update?

P: 1
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.
Expand|Select|Wrap|Line Numbers
  1. Public Class frmCalls
  2.     'database declarations
  3.     Dim MyConnection As OleDbConnection
  4.     Dim callsCommand As OleDbCommand
  5.     Dim callsAdapter As OleDbDataAdapter
  6.     Dim callsTable As DataTable
  7.     Dim callsManager As CurrencyManager
  8.     'variable declarations
  9.     Dim maxrows As Integer
  10.     Dim inc As Integer
  11.     Dim countrows As Integer
  12.     Dim lowestdate As Integer
  13.     Dim testdate As Integer
  14.  
  15.  
  16.     Private Sub frmCalls_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  17.  
  18.         'connect to books database
  19.         MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = c:\leads.mdb")
  20.         'open the connection
  21.         MyConnection.Open()
  22.         'establish command object
  23.         read = "select * " + "from " + Selection
  24.         callsCommand = New OleDbCommand(read, MyConnection)
  25.         'establish data adapter/data table
  26.         callsAdapter = New OleDbDataAdapter()
  27.         callsAdapter.SelectCommand = callsCommand
  28.         callsTable = New DataTable()
  29.         callsAdapter.Fill(callsTable)
  30.         'bind controls to data table
  31.         txtFirst.DataBindings.Add("Text", callsTable, "Borrower First Name")
  32.         txtLast.DataBindings.Add("Text", callsTable, "Borrower Last Name")
  33.         txtCofirst.DataBindings.Add("Text", callsTable, "Co-Borrower First Name")
  34.         txtColast.DataBindings.Add("Text", callsTable, "Co-borrower Last Name")
  35.         txtpropStreet.DataBindings.Add("Text", callsTable, "Property Address")
  36.         txtpropUnit.DataBindings.Add("Text", callsTable, "Property Unit")
  37.         txtpropCity.DataBindings.Add("Text", callsTable, "Property City")
  38.         txtpropState.DataBindings.Add("Text", callsTable, "Property State")
  39.         txtpropZip.DataBindings.Add("Text", callsTable, "Property Zip")
  40.         txtMailStreet.DataBindings.Add("Text", callsTable, "Mailing Address")
  41.         txtMailUnit.DataBindings.Add("Text", callsTable, "Mailing Unit")
  42.         txtMailCity.DataBindings.Add("Text", callsTable, "Mailing City")
  43.         txtMailState.DataBindings.Add("Text", callsTable, "Mailing State")
  44.         txtMailZip.DataBindings.Add("Text", callsTable, "Mailing Zip")
  45.         txthome.DataBindings.Add("Text", callsTable, "Home Phone")
  46.         txtwork.DataBindings.Add("Text", callsTable, "Work Phone")
  47.         txtCell.DataBindings.Add("Text", callsTable, "Cell Phone")
  48.         txtEmail.DataBindings.Add("Text", callsTable, "Email Address")
  49.         txtcurlender.DataBindings.Add("Text", callsTable, "Current Lender")
  50.         txtCuramount.DataBindings.Add("Text", callsTable, "Current Loan Amount")
  51.         txtCurRate.DataBindings.Add("Text", callsTable, "Current Rate")
  52.         txtCurPayment.DataBindings.Add("Text", callsTable, "Current Payment")
  53.         txtCurType.DataBindings.Add("Text", callsTable, "Current Rate Type")
  54.         txtCurDate.DataBindings.Add("Text", callsTable, "Current Origination Date")
  55.         txtBesttime.DataBindings.Add("Text", callsTable, "Best Time")
  56.         txtPurpose.DataBindings.Add("Text", callsTable, "Purpose of Loan")
  57.         txtLasttime.DataBindings.Add("Text", callsTable, "Last Call")
  58.         txtLastdisposition.DataBindings.Add("Text", callsTable, "Last Disposition")
  59.         txtLastlo.DataBindings.Add("Text", callsTable, "Last LO")
  60.         'establish currency manager
  61.         callsManager = DirectCast(Me.BindingContext(callsTable), CurrencyManager)
  62.  
  63.         'find the oldest date
  64.         maxrows = callsTable.Rows.Count
  65.         countrows = 0
  66.         lowestdate = 0
  67.         testdate = 1
  68.         While countrows <> maxrows - 1
  69.             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
  70.                 testdate = testdate + 1
  71.                 countrows = countrows + 1
  72.             Else
  73.                 If callsTable.Rows(testdate).Item(30) = 0 And callsTable.Rows(testdate).Item(31) = 0 And callsTable.Rows(testdate).Item(32) = 0 Then
  74.                     lowestdate = testdate
  75.                     testdate = testdate + 1
  76.                     countrows = countrows + 1
  77.                 Else
  78.                     testdate = testdate + 1
  79.                     countrows = countrows + 1
  80.                 End If
  81.             End If
  82.         End While
  83.  
  84. callsManager.Position = lowestdate
  85.   'update last call time
  86.   callsAdapter.Update(callsTable)
  87.  
  88.         'close the connection
  89.         MyConnection.Close()
  90.         'dispose of the connection object
  91.         MyConnection.Dispose()
  92.         callsCommand.Dispose()
  93.         callsAdapter.Dispose()
  94.         callsTable.Dispose()
  95.     End Sub
Apr 19 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.