Click here to Skip to main content
11,576,064 members (58,034 online)
Rate this: bad
good
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
Edited 7-Aug-12 23:49pm
v2
Comments
Philip Stuyck at 8-Aug-12 5:52am
   
at what line. I don't see any casting here in this code. Your problem might be elsewhere.
16041984 at 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 at 8-Aug-12 5:54am
   
on if statement it gives error
if (DtMain.ToString().Substring(0, 5) == drNameShow.GetString(3).Substring(0, 5))
Prabhakaran Soundarapandian at 8-Aug-12 5:54am
   
Which line you are getting error while debugging?
16041984 at 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 at 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)))
{
Prabhakaran Soundarapandian at 8-Aug-12 6:09am
   
do the same like above what you did and compare..
16041984 at 8-Aug-12 6:16am
   
thx now it's working
thx to Prabhakaran Soundarapandian sir
Prabhakaran Soundarapandian at 8-Aug-12 6:18am
   
Welcome!!!

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 305
1 F-ES Sitecore 145
2 OriginalGriff 125
3 Abhinav S 98
4 Dave Kreskowiak 80
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2015
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