Click here to Skip to main content
12,501,010 members (42,646 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.5
if (DtMain.ToString().Substring(0, 5) == drNameShow.GetString(3).Substring(0, 5))
                {
                    lblPname.Location = new Point(32, 2 + iLblSme);
                    objMain.panNameMain.Controls.Add(this.lblPname);
                    objMain.lblDate.Text = DtMain.ToString().Substring(0, 10);
                    iLblSme = iLblSme + 20;
                    boolSmeDay = true;
                }
it gives error as "Specified cast is not valid."
Posted 7-Aug-12 23:47pm
Updated 7-Aug-12 23:49pm
v2
Comments
Philip Stuyck 8-Aug-12 5:52am
   
at what line. I don't see any casting here in this code. Your problem might be elsewhere.
16041984 8-Aug-12 5:59am
   
on if statement it gives error if (DtMain.ToString().Substring(0, 5) == drNameShow.GetString(3).Substring(0, 5))
plz help.i m newbie
16041984 8-Aug-12 5:54am
   
on if statement it gives error
if (DtMain.ToString().Substring(0, 5) == drNameShow.GetString(3).Substring(0, 5))
   
Which line you are getting error while debugging?
16041984 8-Aug-12 5:59am
   
on if statement it gives error if (DtMain.ToString().Substring(0, 5) == drNameShow.GetString(3).Substring(0, 5))
plz help.i m newbie

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

if drNameShow is datareader means try the below code.

string mystring = drNameShow["columnName"].ToString();
if (DtMain.ToString().Substring(0, 5) == mystring.Substring(0, 5))
  Permalink  
Comments
16041984 8-Aug-12 6:03am
   
it's working also i have error on code
if ((DtAdv1.ToString().Substring(0, 5) == drNameShow.GetString(3).Substring(0, 5)) || (DtAdv2.ToString().Substring(0, 5) == drNameShow.GetString(3).Substring(0, 5)))
{
   
do the same like above what you did and compare..
16041984 8-Aug-12 6:16am
   
thx now it's working
thx to Prabhakaran Soundarapandian sir
   
Welcome!!!

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.160919.1 | Last Updated 8 Aug 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