Click here to Skip to main content
12,397,805 members (46,759 online)
Rate this:
 
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2016
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