Click here to Skip to main content
15,125,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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
Updated 8-Aug-12 0:49am
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

if drNameShow is datareader means try the below code.

C#
string mystring = drNameShow["columnName"].ToString();
if (DtMain.ToString().Substring(0, 5) == mystring.Substring(0, 5))
   
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)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900