Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

try below code
C#
if(drNameShow["Time"] != System.DBNull.Value)
   {
      string mystring4= drNameShow["Time"].ToString();
   }
   else
   {
       string mystring4 = "NULL";
   }
 
Share this answer
 
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  }
 
Share this answer
 
v2
hi,

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


Thanks,
Viprat
 
Share this answer
 

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