|
-
May 9th, 2005, 09:07 AM
#1
Thread Starter
Lively Member
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:
'Public declarations
Dim con As New Odbc.OdbcConnection
Dim ds As New DataSet
Dim da As Odbc.OdbcDataAdapter
Dim sql As String
Dim inc As Integer
Dim maxrows As Integer
'Form Load
Private Sub PartsManager_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = [LONG ODBC CONNECTION STRING IS HERE]
con.Open()
sql = "SELECT * FROM customer ORDER BY customername ASC;"
da = New Odbc.OdbcDataAdapter(sql, con)
da.Fill(ds, "customer")
maxrows = ds.Tables("Customer").Rows.Count
inc = 0
NavigateRecords() 'References another sub that tells where to put what, basically
End Sub
'The Delete button code
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim cb As New Odbc.OdbcCommandBuilder(da)
ds.Tables("customer").Rows(inc).Delete()
maxrows = maxrows - 1
inc = 0
NavigateRecords()
da.Update(ds, "customer")
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.
-
May 10th, 2005, 07:55 AM
#2
Thread Starter
Lively Member
Re: Can't Delete First Record...
-
May 11th, 2005, 01:34 PM
#3
Thread Starter
Lively Member
Re: Can't Delete First Record...
Surely, somebody knows what the problem is here.
CP
-
May 11th, 2005, 02:15 PM
#4
Addicted Member
Re: Can't Delete First Record...
this is what my delete code looks like
VB Code:
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim intcurrent As Integer = Me.BindingContext(DsSQL1, "dem").Position
DsSQL1.Dem.Rows(intcurrent).Delete()
blnIsDirty = True
displayrecordposition()
dssql is my dataset and dem is the table name.
hope that helps
-
May 11th, 2005, 03:06 PM
#5
Lively Member
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
-
May 11th, 2005, 03:09 PM
#6
Lively Member
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?
-
May 11th, 2005, 03:12 PM
#7
Thread Starter
Lively Member
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.
-
May 11th, 2005, 03:31 PM
#8
Thread Starter
Lively Member
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:
Private Sub NavigateRecords()
txtCustomerName.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("customername")), "", ds.Tables("customer").Rows(inc).Item("customername")).ToString
txtCustomerNumber.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("customernumber")), "", ds.Tables("customer").Rows(inc).Item("customernumber")).ToString
txtCustomerAddress.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("streetaddress")), "", ds.Tables("customer").Rows(inc).Item("streetaddress")).ToString
txtCustomerAddress2.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("streetaddress2")), "", ds.Tables("customer").Rows(inc).Item("streetaddress2")).ToString
txtCustomerPOBox.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("pobox")), "", ds.Tables("customer").Rows(inc).Item("pobox")).ToString
txtCustomerCity.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("city")), "", ds.Tables("customer").Rows(inc).Item("city")).ToString
txtCustomerState.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("state")), "", ds.Tables("customer").Rows(inc).Item("state")).ToString
txtCustomerZip.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("postalcode")), "", ds.Tables("customer").Rows(inc).Item("postalcode")).ToString
txtCustomerContact.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("contact")), "", ds.Tables("customer").Rows(inc).Item("contact")).ToString
txtCustomerPhone.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("contactphone")), "", ds.Tables("customer").Rows(inc).Item("contactphone")).ToString
txtCustomerNotes.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("notes")), "", ds.Tables("customer").Rows(inc).Item("notes")).ToString
txtCustomerLastUpdate.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("lastupdate")), "", ds.Tables("customer").Rows(inc).Item("lastupdate")).ToString
txtCustomerUpdatedBy.Text = IIf(IsDBNull(ds.Tables("customer").Rows(inc).Item("updatedby")), "", ds.Tables("customer").Rows(inc).Item("updatedby")).ToString
Try
txtCustomerName.Text = ds.Tables("customer").Rows(inc).Item(0)
txtCustomerNumber.Text = ds.Tables("customer").Rows(inc).Item(1)
txtCustomerAddress.Text = ds.Tables("customer").Rows(inc).Item(2)
txtCustomerAddress2.Text = ds.Tables("customer").Rows(inc).Item(3)
txtCustomerPOBox.Text = ds.Tables("customer").Rows(inc).Item(4)
txtCustomerCity.Text = ds.Tables("customer").Rows(inc).Item(5)
txtCustomerState.Text = ds.Tables("customer").Rows(inc).Item(6)
txtCustomerZip.Text = ds.Tables("customer").Rows(inc).Item(7)
txtCustomerContact.Text = ds.Tables("customer").Rows(inc).Item(8)
txtCustomerPhone.Text = ds.Tables("customer").Rows(inc).Item(9)
txtCustomerNotes.Text = ds.Tables("customer").Rows(inc).Item(10)
txtCustomerLastUpdate.Text = ds.Tables("customer").Rows(inc).Item(11)
txtCustomerUpdatedBy.Text = ds.Tables("customer").Rows(inc).Item(12)
Catch ex As Exception
MsgBox("Returning Null Values")
End Try
End Sub
Thanks,
CP
Last edited by milkmood; May 11th, 2005 at 03:45 PM.
-
May 11th, 2005, 03:50 PM
#9
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|