getchanges returns nothing

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,

Here is my code :

For Each row As DataRow In m_dsTabs.Tables(0).Rows
If CInt(row("TabId")) = DirectCast(tabQryTabs.SelectedTab,
QueryTabPage).TabId Then
m_dsTabs.Tables(0).Rows.Remove(row)
Exit For
End If
Next
m_dsTabs.AcceptChanges()
m_dsTabs.GetChanges(DataRowState.Deleted)

GetChanges returns nothing. Why ? And do you think my method for
removing a row given a particular TabId (primary key of my table) is a
good way to do so?

Thx
 
Sam said:
Hi,

Here is my code :

For Each row As DataRow In m_dsTabs.Tables(0).Rows
If CInt(row("TabId")) = DirectCast(tabQryTabs.SelectedTab,
QueryTabPage).TabId Then
m_dsTabs.Tables(0).Rows.Remove(row)
Exit For
End If
Next
m_dsTabs.AcceptChanges()
m_dsTabs.GetChanges(DataRowState.Deleted)

GetChanges returns nothing. Why ?

Because you called AcceptChanges, and this removes the deleted rows from the
table. Afterwards, there are no rows with rowstate=deleted in the table and
getchanges returns nothing.
And do you think my method for
removing a row given a particular TabId (primary key of my table) is
a good way to do so?


dim id as integer
dim row as datarow

id = DirectCast(tabQryTabs.SelectedTab, QueryTabPage).TabId
row = m_dsTabs.Tables(0).Rows.Find(ID)
if not row is nothing then row.Delete

is probably faster (or shorter (or easier)).

Armin
 
Actually I've got the error :
System.Data.MissingPrimaryKeyException - Table doesn't have a primary
key.
on that line

row = m_dsTabs.Tables(0).Rows.Find(TabId)

TabId is the primary key in my database's table but I don't know how to
set it to be my primary key in my dataset ??
 
Ok, I've found out :)

Dim pk(0) As DataColumn
pk(0) = m_dsTabs.Tables(0).Columns("TabId")
m_dsTabs.Tables(0).PrimaryKey = pk

Now it works .

Thx again
 
Ok, I've found out :)

Dim pk(0) As DataColumn
pk(0) = m_dsTabs.Tables(0).Columns("TabId")
m_dsTabs.Tables(0).PrimaryKey = pk

Now it works .

Thx again
 
Actually I have another problem related to this:

dt = m_dsTabs.Tables(0).GetChanges(DataRowState.Deleted)

If I try to access dt.Rows(0).Item("TabID") then I get :

System.Data.DeletedRowInaccessibleException - Deleted row information
cannot be accessed through the row.

I would have thought that dt would contain the data of the deleted row
?
If not, how can I get this information ?

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top