Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.5
on the line error come as
 
No data exists for the row/column. thx in advance....time is column in database
 
string mystring4 = drNameShow["Time"].ToString();
Posted 3-Sep-12 0:44am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try below code
 if(drNameShow["Time"] != System.DBNull.Value) 
    { 
       string mystring4= drNameShow["Time"].ToString(); 
    } 
    else 
    { 
        string mystring4 = "NULL"; 
    } 
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check if the datareader has any rows before trying to access the columns in that row.
Read returns a bool indicating if there is any value available.
 
e.g.
if (drNameShow.Read())    
 { //processing here  }
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi,
 
try the following code. It may be help you.
if (!string.IsNullOrEmpty(drNameShow["Time"].ToString()))
{
string mystring4= drNameShow["Time"].ToString();
}
else
{
string mystring4 = string.Empty;
}
 
Thanks,
Viprat
  Permalink  

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

  Print Answers RSS
0 Maciej Los 590
1 OriginalGriff 535
2 CPallini 285
3 Peter Leow 185
4 RyanDev 161
0 OriginalGriff 5,784
1 Sergey Alexandrovich Kryukov 4,838
2 Peter Leow 3,009
3 Maciej Los 2,894
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100