Results 1 to 9 of 9

Thread: Can't Delete First Record...[RESOLVED - enough]

  1. #1

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Resolved Can't Delete First Record...[RESOLVED - enough]

    What am I missing? When I try to delete the first record (and only the first record) in my PostgreSQL DB, I get an error that says:

    An unhandled exception of type 'System.Data.DeletedRowInaccessibleException' occurred in system.data.dll

    Additional information: Deleted row information cannot be accessed through the row.


    VB Code:
    1. 'Public declarations
    2.  
    3.     Dim con As New Odbc.OdbcConnection
    4.     Dim ds As New DataSet
    5.     Dim da As Odbc.OdbcDataAdapter
    6.     Dim sql As String
    7.     Dim inc As Integer
    8.     Dim maxrows As Integer
    9.  
    10.  
    11. 'Form Load
    12.  
    13.     Private Sub PartsManager_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    14.  
    15.             con.ConnectionString = [LONG ODBC CONNECTION STRING IS HERE]
    16.  
    17.             con.Open()
    18.             sql = "SELECT * FROM customer ORDER BY customername ASC;"
    19.  
    20.             da = New Odbc.OdbcDataAdapter(sql, con)
    21.  
    22.             da.Fill(ds, "customer")
    23.  
    24.             maxrows = ds.Tables("Customer").Rows.Count
    25.  
    26.             inc = 0
    27.  
    28.             NavigateRecords()  'References another sub that tells where to put what, basically
    29.  
    30.     End Sub
    31.  
    32.  
    33. 'The Delete button code
    34.  
    35.     Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    36.         Dim cb As New Odbc.OdbcCommandBuilder(da)
    37.         ds.Tables("customer").Rows(inc).Delete()
    38.         maxrows = maxrows - 1
    39.         inc = 0
    40.         NavigateRecords()
    41.         da.Update(ds, "customer")
    42.     End Sub

    Thanks in advance...Let me know if there's something else you need.
    CP
    Last edited by milkmood; May 11th, 2005 at 03:52 PM.

  2. #2

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Can't Delete First Record...

    Anyone?

  3. #3

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Can't Delete First Record...

    Surely, somebody knows what the problem is here.
    CP

  4. #4
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: Can't Delete First Record...

    this is what my delete code looks like
    VB Code:
    1. Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    2.         Dim intcurrent As Integer = Me.BindingContext(DsSQL1, "dem").Position
    3.         DsSQL1.Dem.Rows(intcurrent).Delete()
    4.         blnIsDirty = True
    5.         displayrecordposition()
    dssql is my dataset and dem is the table name.
    hope that helps

  5. #5
    Lively Member
    Join Date
    Jun 2004
    Posts
    99

    Re: Can't Delete First Record...

    Is it because you are using the variable 'inc' before it is declared or set?
    Have you stepped through checking its value?

    Code:
            ds.Tables("customer").Rows(inc).Delete()
            maxrows = maxrows - 1
            inc = 0

  6. #6
    Lively Member
    Join Date
    Jun 2004
    Posts
    99

    Re: Can't Delete First Record...

    Ok, now I see that inc is public and set in load.

    What about the code for NavigateRecords()? Is that where it's crashing?

  7. #7

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Can't Delete First Record...

    That is indeed where it's crashing. As soon as I can disconnect from the VPN I'm on, I'll try it again, and insert the NavigateRecords() routine here.

  8. #8

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Can't Delete First Record...

    Here's the NavigateRecords() code which I use throughout my application at various times, ie., after an update, insert, etc. When it crashes while trying to delete the first record, it highlights (in green) the first line and gives me the error I mentioned in my original post. If I comment out the first line, it crashes on the second, and so on. (EDIT) If I comment out the whole top half of the routine, it kind of works, but I have to catch a null exception in the NavigateRecords routine. (/EDIT)

    I realize that the code is probably redundant and/or excessive, but I'm pretty green at programming in general and much of "my" code is put together from various sources and helpers, and I don't really know how to step through it.
    VB Code:
    1. Private Sub NavigateRecords()
    2.  
    3.         txtCustomerName.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("customername")), "", ds.Tables("customer").Rows(inc).Item("customername")).ToString
    4.         txtCustomerNumber.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("customernumber")), "", ds.Tables("customer").Rows(inc).Item("customernumber")).ToString
    5.         txtCustomerAddress.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("streetaddress")), "", ds.Tables("customer").Rows(inc).Item("streetaddress")).ToString
    6.         txtCustomerAddress2.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("streetaddress2")), "", ds.Tables("customer").Rows(inc).Item("streetaddress2")).ToString
    7.         txtCustomerPOBox.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("pobox")), "", ds.Tables("customer").Rows(inc).Item("pobox")).ToString
    8.         txtCustomerCity.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("city")), "", ds.Tables("customer").Rows(inc).Item("city")).ToString
    9.         txtCustomerState.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("state")), "", ds.Tables("customer").Rows(inc).Item("state")).ToString
    10.         txtCustomerZip.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("postalcode")), "", ds.Tables("customer").Rows(inc).Item("postalcode")).ToString
    11.         txtCustomerContact.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("contact")), "", ds.Tables("customer").Rows(inc).Item("contact")).ToString
    12.         txtCustomerPhone.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("contactphone")), "", ds.Tables("customer").Rows(inc).Item("contactphone")).ToString
    13.         txtCustomerNotes.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("notes")), "", ds.Tables("customer").Rows(inc).Item("notes")).ToString
    14.         txtCustomerLastUpdate.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("lastupdate")), "", ds.Tables("customer").Rows(inc).Item("lastupdate")).ToString
    15.         txtCustomerUpdatedBy.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("updatedby")), "", ds.Tables("customer").Rows(inc).Item("updatedby")).ToString
    16.  
    17.         Try
    18.  
    19.             txtCustomerName.Text = ds.Tables("customer").Rows(inc).Item(0)
    20.             txtCustomerNumber.Text = ds.Tables("customer").Rows(inc).Item(1)
    21.             txtCustomerAddress.Text = ds.Tables("customer").Rows(inc).Item(2)
    22.             txtCustomerAddress2.Text = ds.Tables("customer").Rows(inc).Item(3)
    23.             txtCustomerPOBox.Text = ds.Tables("customer").Rows(inc).Item(4)
    24.             txtCustomerCity.Text = ds.Tables("customer").Rows(inc).Item(5)
    25.             txtCustomerState.Text = ds.Tables("customer").Rows(inc).Item(6)
    26.             txtCustomerZip.Text = ds.Tables("customer").Rows(inc).Item(7)
    27.             txtCustomerContact.Text = ds.Tables("customer").Rows(inc).Item(8)
    28.             txtCustomerPhone.Text = ds.Tables("customer").Rows(inc).Item(9)
    29.             txtCustomerNotes.Text = ds.Tables("customer").Rows(inc).Item(10)
    30.             txtCustomerLastUpdate.Text = ds.Tables("customer").Rows(inc).Item(11)
    31.             txtCustomerUpdatedBy.Text = ds.Tables("customer").Rows(inc).Item(12)
    32.  
    33.         Catch ex As Exception
    34.             MsgBox("Returning Null Values")
    35.         End Try
    36.     End Sub
    Thanks,
    CP
    Last edited by milkmood; May 11th, 2005 at 03:45 PM.

  9. #9

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Can't Delete First Record...

    Referencing the EDIT above: I can move the TRY to the top of the first half of the NavigateRecords routine and catch the same exception. It works, it's just kind of a hack job. I don't see the user deleting the very first record of an ordered data list all that often, so it's not a big deal. The refresh button I have makes everything happy again.

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