Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Dear friends,

I have the following code block in my program-

dim RowPostion as integer 
If dt.Rows.Count > 0 Then
  MsgBox(dt.Rows(RowPostion)(0).ToString) 
  MsgBox(dt.Rows(RowPostion )(1).ToString) 
  dt.Rows.RemoveAt(RowPostion) 
End If


Problem is, i am able to read values, but fail to delete. It returns "There is no row at position(..)" while trying to remove the row.


I cound not find any solution.
Would you please help me regarding this issue?

SKPaul.
Posted
Updated 17-Dec-11 19:56pm
v4
Comments
Sergey Alexandrovich Kryukov 18-Dec-11 1:43am    
How can you see it "fails"? Did you run it under debugger? Are you sure this fragment of code is executed only once? Why you call it only if there is only 1 row?
--SA
Saumitra Kumar Paul 18-Dec-11 1:48am    
Dear SAKryukov,
Thank you for your reply. Well, rewrite it-

dim RowPostion as integer
If dt.Rows.Count > 0 Then
MsgBox(dt.Rows(RowPostion)(0).ToString)
MsgBox(dt.Rows(RowPostion )(1).ToString)
dt.Rows.RemoveAt(RowPostion)
End If

Problem is, i am able to read values, but fail to delete. It returns "There is no row at position(..)" while trying to remove the row.
thatraja 18-Dec-11 2:30am    
Whats the value of RowPostion?
coded007 18-Dec-11 5:59am    
i believe the problem is with

dt.Rows.RemoveAt(RowPostion)

statement please remove and check it

1 solution

I hope the problem is because you didn't specified a starting value for the row position

try this
VB
Dim RowPosition as integer = 0
If dt.Rows.Count > 0 Then
  MsgBox(dt.Rows(RowPostion)(0).ToString)
  MsgBox(dt.Rows(RowPostion )(1).ToString)
  dt.Rows.RemoveAt(RowPostion)
End If



(First check the value of data row count and Row position then try to set the value of Row position one step back to its original position, if the RowPosition is starting with 1)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900