PC Review


Reply
Thread Tools Rate Thread

Deleting Rows From DataTable

 
 
John Zink
Guest
Posts: n/a
 
      27th Aug 2003
If I call the delete method on a datatable that is
returned from a web service the delete appears to work,
but the row is still in the rows collection. I do not
receive any errors, but if after the delete I loop thru
the rows collection with a for each loop I get an error
when I hit the row. After I call AcceptChanges the row is
gone and I can get around the for each problem by checking
the rowstate, but I thought that after calling delete it
wouldn't be accessible. Also after the delete the
rowCount is not decremented.
Here is the code snippet:

Dim oServices As New UWEngineServices.UWEngineServices()
oDS = oServices.GetRulesetInfo("d067268", txtRSId.Text)

'shows 1
MessageBox.Show(oDS.UW_RULESETS.Count)
'shows false
MessageBox.Show(oDS.HasErrors)
oDS.UW_RULESETS(0).Delete()
'shows 1
MessageBox.Show(oDS.UW_RULESETS.Count)
'shows false
MessageBox.Show(oDS.HasErrors)
 
Reply With Quote
 
 
 
 
One Handed Man
Guest
Posts: n/a
 
      27th Aug 2003
it wont delete until you update using the datadapters update method

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET

==============================
"John Zink" <(E-Mail Removed)> wrote in message
news:0d1701c36c99$e2b6c210$(E-Mail Removed)...
> If I call the delete method on a datatable that is
> returned from a web service the delete appears to work,
> but the row is still in the rows collection. I do not
> receive any errors, but if after the delete I loop thru
> the rows collection with a for each loop I get an error
> when I hit the row. After I call AcceptChanges the row is
> gone and I can get around the for each problem by checking
> the rowstate, but I thought that after calling delete it
> wouldn't be accessible. Also after the delete the
> rowCount is not decremented.
> Here is the code snippet:
>
> Dim oServices As New UWEngineServices.UWEngineServices()
> oDS = oServices.GetRulesetInfo("d067268", txtRSId.Text)
>
> 'shows 1
> MessageBox.Show(oDS.UW_RULESETS.Count)
> 'shows false
> MessageBox.Show(oDS.HasErrors)
> oDS.UW_RULESETS(0).Delete()
> 'shows 1
> MessageBox.Show(oDS.UW_RULESETS.Count)
> 'shows false
> MessageBox.Show(oDS.HasErrors)



 
Reply With Quote
 
John Zink
Guest
Posts: n/a
 
      27th Aug 2003
I am using the dataset in a disconnected mode.
I realize that the database will not get updated until I
call the update method, but the disconnected dataset
should properly reflect the changes after I call the delete
() method.

Here is a simple example that demonstrates my point:

Dim oDS As New DataSet()
Dim oTbl As New DataTable()
Dim oRow As DataRow

oTbl.Columns.Add("column1")
oTbl.Columns.Add("column2")
oRow = oTbl.NewRow
oRow(0) = "A"
oRow(1) = "B"
oTbl.Rows.Add(oRow)
'shows 1
MessageBox.Show(oTbl.Rows.Count)
oTbl.Rows(0).Delete()
'shows 0
MessageBox.Show(oTbl.Rows.Count)

After the delete the rowcount goes to 0. In my original
post the rowcount does not decrement after the delete.
Why ????

>-----Original Message-----
>it wont delete until you update using the datadapters

update method
>
>--
>Regards - One Handed Man
>
>Author : Fish .NET & Keep .NET
>
>==============================
>"John Zink" <(E-Mail Removed)> wrote in message
>news:0d1701c36c99$e2b6c210$(E-Mail Removed)...
>> If I call the delete method on a datatable that is
>> returned from a web service the delete appears to work,
>> but the row is still in the rows collection. I do not
>> receive any errors, but if after the delete I loop thru
>> the rows collection with a for each loop I get an error
>> when I hit the row. After I call AcceptChanges the row

is
>> gone and I can get around the for each problem by

checking
>> the rowstate, but I thought that after calling delete it
>> wouldn't be accessible. Also after the delete the
>> rowCount is not decremented.
>> Here is the code snippet:
>>
>> Dim oServices As New UWEngineServices.UWEngineServices()
>> oDS = oServices.GetRulesetInfo("d067268", txtRSId.Text)
>>
>> 'shows 1
>> MessageBox.Show(oDS.UW_RULESETS.Count)
>> 'shows false
>> MessageBox.Show(oDS.HasErrors)
>> oDS.UW_RULESETS(0).Delete()
>> 'shows 1
>> MessageBox.Show(oDS.UW_RULESETS.Count)
>> 'shows false
>> MessageBox.Show(oDS.HasErrors)

>
>
>.
>

 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      27th Aug 2003
Perhaps you need to call AccepChanges() after updating the
database.

>-----Original Message-----
>I am using the dataset in a disconnected mode.
>I realize that the database will not get updated until I
>call the update method, but the disconnected dataset
>should properly reflect the changes after I call the

delete
>() method.
>
>Here is a simple example that demonstrates my point:
>
> Dim oDS As New DataSet()
> Dim oTbl As New DataTable()
> Dim oRow As DataRow
>
> oTbl.Columns.Add("column1")
> oTbl.Columns.Add("column2")
> oRow = oTbl.NewRow
> oRow(0) = "A"
> oRow(1) = "B"
> oTbl.Rows.Add(oRow)
> 'shows 1
> MessageBox.Show(oTbl.Rows.Count)
> oTbl.Rows(0).Delete()
> 'shows 0
> MessageBox.Show(oTbl.Rows.Count)
>
>After the delete the rowcount goes to 0. In my original
>post the rowcount does not decrement after the delete.
>Why ????
>
>>-----Original Message-----
>>it wont delete until you update using the datadapters

>update method
>>
>>--
>>Regards - One Handed Man
>>
>>Author : Fish .NET & Keep .NET
>>
>>==============================
>>"John Zink" <(E-Mail Removed)> wrote in message
>>news:0d1701c36c99$e2b6c210$(E-Mail Removed)...
>>> If I call the delete method on a datatable that is
>>> returned from a web service the delete appears to work,
>>> but the row is still in the rows collection. I do not
>>> receive any errors, but if after the delete I loop thru
>>> the rows collection with a for each loop I get an error
>>> when I hit the row. After I call AcceptChanges the row

>is
>>> gone and I can get around the for each problem by

>checking
>>> the rowstate, but I thought that after calling delete

it
>>> wouldn't be accessible. Also after the delete the
>>> rowCount is not decremented.
>>> Here is the code snippet:
>>>
>>> Dim oServices As New UWEngineServices.UWEngineServices

()
>>> oDS = oServices.GetRulesetInfo("d067268", txtRSId.Text)
>>>
>>> 'shows 1
>>> MessageBox.Show(oDS.UW_RULESETS.Count)
>>> 'shows false
>>> MessageBox.Show(oDS.HasErrors)
>>> oDS.UW_RULESETS(0).Delete()
>>> 'shows 1
>>> MessageBox.Show(oDS.UW_RULESETS.Count)
>>> 'shows false
>>> MessageBox.Show(oDS.HasErrors)

>>
>>
>>.
>>

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting Rows from a DataTable... karthick Microsoft ASP .NET 2 14th Feb 2007 11:07 PM
newbie question on deleting rows from DataTable Tim Holgerson Microsoft C# .NET 2 13th Aug 2004 02:32 PM
DataViews and deleting rows in the DataTable Jon Skeet [C# MVP] Microsoft ADO .NET 9 6th Aug 2004 09:26 AM
Deleting rows from a DataTable in a DataSet =?Utf-8?B?TWljaGFlbA==?= Microsoft ADO .NET 4 23rd Jan 2004 01:43 AM
Deleting rows from a datatable Neil Microsoft ADO .NET 3 8th Aug 2003 05:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 PM.