Results 1 to 13 of 13

Thread: Access Database not updating

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52

    Access Database not updating

    Ok, I'm back. I have a program that half works. It has a connection to an Access database with 2 data adapters. Each data adapter fills a dataset. I then dim a datatable from each dataset. I'll post the code and then explain what the problem is. Here is the code:
    VB Code:
    1. Private Sub btnLoadParcels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadParcels.Click
    2.         Dim reccount, whereiam, whereiam2, count2, addcount As Integer
    3.         Dim textline, formfield, adddisp As String
    4.         Dim tempdate As DateTime
    5.         Dim firsttime, foundparcel, foundowner As Boolean
    6.         firsttime = True
    7.         Dim dsparcel As New DataSet()
    8.         Dim dsparcelowner As New DataSet()
    9.         DaParcel.Fill(dsparcel)
    10.         DaParcelOwner.Fill(dsparcelowner)
    11.         Dim dtparcel As DataTable = dsparcel.Tables(0)
    12.         Dim dtparcelowner As DataTable = dsparcelowner.Tables(0)
    13.         FileOpen(1, "\\INFORMIX\GISDATA\cnci.txt", OpenMode.Binary, OpenAccess.Read, OpenShare.Shared)
    14.         While Not EOF(1)
    15.             count2 = count2 + 1
    16.             textline = LineInput(1)
    17.             Dim fieldarray() As String = textline.Split("|")
    18.             If firsttime = True Then
    19.             Else
    20.                 reccount = 0
    21.                 formfield = fieldarray(1)
    22.                 formfield = Mid(formfield, 1, 2) + "." + Mid(formfield, 3, 2) + "." + Mid(formfield, 5, 3) + "." + Mid(formfield, 8, 3)
    23.                 Do Until (reccount = dtparcel.Rows.Count)
    24.                     If dtparcel.Rows(reccount).Item("parcel-number") = formfield Then
    25.                         foundparcel = True
    26.                         whereiam = reccount
    27.                         reccount = dtparcel.Rows.Count - 1
    28.                     Else
    29.                         foundparcel = False
    30.                     End If
    31.                     reccount = reccount + 1
    32.                 Loop
    33.                 reccount = 0
    34.                 Do Until (reccount = dtparcelowner.Rows.Count)
    35.                     If dtparcelowner.Rows(reccount).Item("parcel_no") = formfield Then
    36.                         foundowner = True
    37.                         whereiam2 = reccount
    38.                         reccount = dtparcelowner.Rows.Count - 1
    39.                     Else
    40.                         foundowner = False
    41.                     End If
    42.                     reccount = reccount + 1
    43.                 Loop
    44.                 If foundparcel = True And foundowner = True Then
    45.                     dtparcelowner.Rows(whereiam2).Item("owner-name") = fieldarray(2)
    46.                     dtparcelowner.Rows(whereiam2).Item("owner-addr1") = fieldarray(3)
    47.                     dtparcelowner.Rows(whereiam2).Item("owner-addr2") = fieldarray(4)
    48.                     dtparcelowner.Rows(whereiam2).Item("owner-addr3") = fieldarray(5)
    49.                     dtparcelowner.Rows(whereiam2).Item("owner-zip5") = fieldarray(6)
    50.                     dtparcelowner.Rows(whereiam2).Item("owner-zip4") = fieldarray(7)
    51.                     dtparcelowner.Rows(whereiam2).Item("township") = fieldarray(0)
    52.                     dtparcel.Rows(whereiam).Item("addr-number") = fieldarray(8)
    53.                     dtparcel.Rows(whereiam).Item("addr-street") = fieldarray(9)
    54.                     dtparcel.Rows(whereiam).Item("parcel-lgl-desc") = fieldarray(18) + " " + fieldarray(19) + " " + fieldarray(20) + " " + fieldarray(21)
    55.                     dtparcel.Rows(whereiam).Item("parcel-township") = fieldarray(0)
    56.                     dtparcel.Rows(whereiam).Item("parcel-status") = fieldarray(25)
    57.                     If fieldarray(24) = "" Then
    58.                         tempdate = #1/1/1000#
    59.                     Else
    60.                         tempdate = CDate(fieldarray(24))
    61.                     End If
    62.                     dtparcel.Rows(whereiam).Item("update-date") = tempdate
    63.                     Try
    64.                         DaParcel.Update(dtparcel)
    65.                         DaParcelOwner.Update(dtparcelowner)
    66.                     Catch ex As DBConcurrencyException
    67.                     End Try
    68.                 ElseIf foundparcel = True And foundowner = False Then
    69.                 ElseIf foundparcel = False And foundowner = True Then
    70.                 ElseIf foundparcel = False And foundowner = False Then
    71.                     Dim newrow As DataRow = dtparcelowner.NewRow
    72.                     newrow("parcel_no") = formfield
    73.                     newrow("owner-name") = fieldarray(2)
    74.                     newrow("owner-addr1") = fieldarray(3)
    75.                     newrow("owner-addr2") = fieldarray(4)
    76.                     newrow("owner-addr3") = fieldarray(5)
    77.                     newrow("owner-zip5") = fieldarray(6)
    78.                     newrow("owner-zip4") = fieldarray(7)
    79.                     newrow("township") = fieldarray(0)
    80.                     dtparcelowner.Rows.Add(newrow)
    81.                     dtparcelowner.AcceptChanges()
    82.                     Dim newrow2 As DataRow = dtparcel.NewRow
    83.                     newrow2("addr-number") = fieldarray(8)
    84.                     newrow2("addr-street") = fieldarray(9)
    85.                     newrow2("parcel-lgl-desc") = fieldarray(18) + " " + fieldarray(19) + " " + fieldarray(20) + " " + fieldarray(21)
    86.                     newrow2("parcel-number") = fieldarray(1)
    87.                     newrow2("parcel-township") = fieldarray(0)
    88.                     newrow2("parcel-status") = fieldarray(25)
    89.                     If fieldarray(24) = "" Then
    90.                         tempdate = #1/1/1000#
    91.                     Else
    92.                         tempdate = CDate(fieldarray(24))
    93.                     End If
    94.                     newrow2("update-date") = tempdate
    95.                     dtparcel.Rows.Add(newrow2)
    96.                     DaParcel.Update(dsparcel)
    97.                     DaParcelOwner.Update(dsparcelowner)
    98.                     addcount = addcount + 1
    99.                 End If
    100.             End If
    101.             firsttime = False
    102.             txtNumber.Text = count2
    103.             txtNumber.Refresh()
    104.         End While
    105.         FileClose(1)
    106.         MsgBox("Done", MsgBoxStyle.OKOnly, "Message")
    107.         adddisp = addcount & " parcel records added."
    108.         MsgBox(adddisp, MsgBoxStyle.OKOnly, "Added Count")
    109.     End Sub
    I have 2 problems:
    1. The first condition, where foundparcel and foundowner are true does not happen. It goes thorough the loop as it should but it does not update the database at all.
    2. The last condition, where foundparcel and foundowner are false partly happens. It does add some of the records but my add count is like 2500 and the database only shows about 300 more records? Help!

    Thanks...

    shootsnlad

    PS: Yes, edneeis, this will look familiar to you. (It's almost done!)

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    This beast again huh. With complex things like this its good to have some example data. Can you provide a small bit of the text file and maybe the database info in an xml file? Then we could test and find the problem.

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52
    Here is the data file...

    Thanks...

    shootsnlad

  4. #4

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52
    I can't attach the database. It's 182k with only 2 tables 3 records each. Max size on here is 100k. Any ideas?
    Thanks

    shootsnlad

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Can you zip to get it under the 100k?

  6. #6

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52
    Here it is....

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I haven't forgotten you I've just been really busy and had some technical difficulties, I'll try to help out tonight or tomorrow.

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Whats the SQL for the data adapters? DaParcel and DaParcelOwner what type of data are they connecting to?

  9. #9

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52
    The SQL was generated after I had dragged the Data Adapters to the form. I let VB generate the commands. As for the type of data, it's just the Access Database.

  10. #10

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52
    Edneeis,

    After doing some more testing it appears as though one table is working and the other isn't. The parcel table in Access is updating with changes, and add's are being taken. The parcelowner table in Access is not getting updated and add's are not being taken. The code for the two looks the same to me. Any ideas?

    Thanks!

    shootsnlad

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try removing the 'dtparcelowner.AcceptChanges()' line right after you add the new row. This method is misleading, it says that the updates have already been done and will then not perform them during the next update. Its sort of like setting the IsDirty flag back to false.

  12. #12

    Thread Starter
    Registered User
    Join Date
    Jul 2000
    Posts
    52
    That did it! Works fine now. Thanks! I appreciate the help...

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    No problem. I was a bit slower than usual, but better late than never.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width