Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if (dt.Rows[0] !=null)

if condition satisfy it wii enter else return

its giving error there is no value at position 0
Posted
Comments
Manoj Sawant 1-Dec-15 5:57am    
post you code
[no name] 1-Dec-15 5:58am    
Check first whether there are rows. E.g. dt.Rows.Count.
Kornfeld Eliyahu Peter 1-Dec-15 6:11am    
You should post it as the solution!
[no name] 1-Dec-15 6:16am    
Thank you for the Motivation, I try it.

It Looks like your dt.Rows is empty, means does not contain rows. You can verify this by checking dt.Rows.Count. After confirming this, you Need to find the reason why the table does not have rows.

I hope this helps.
 
Share this answer
 
Comments
CPallini 1-Dec-15 6:21am    
Of course. 5.
[no name] 1-Dec-15 6:22am    
Thank you very much.
Sergey Alexandrovich Kryukov 1-Dec-15 14:49pm    
Sure, a 5.
—СА
[no name] 2-Dec-15 4:00am    
Thank you very much.
Error is pretty much self-explanatory: "there is no value at position 0" - Meaning, your datatable doesn't contain any records/rows.

Workaround-
C#
if(dt.Rows.Count > 0)
{
    if (dt.Rows[0] !=null)
    {
        // do something awesome here
    }
}


-KR
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Dec-15 14:49pm    
Sure, a 5.
—SA

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