Weird VS and C# issue

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Weird VS and C# issue

Post by hallsofvallhalla »

Not sure if anyone has run into this before but the only thing I can think of is a VS issue.



I am simply calling a method and putting the return result in an int variable. However VS says its a string

Code: Select all

  public int ADPTime = 0;
        public int ADPId;
        private ADPFunctions ADP = new ADPFunctions();

        public void GetADPId()
        {
            ADPId = ADP.GetADPId(this.Id);
        }

        public void GetADPTime(string Start, string End)
        {
            ADPTime = ADP.GetADPTime(Start, End, this.ADPId); <---------This is where I get first error
        }

Then you can see here it is an int. Yet I get an error saying cannot convert Int to string then another error, cannot convert string to int

Code: Select all

 public string GetADPTime(string Start, string End,string ADPId)
        {
            int ADPTime = 0;
            List<string> Times = new List<string>();
            SqlConnection thisConnection = *removed
            thisConnection.Open();
            SqlCommand thisCommand = thisConnection.CreateCommand();
            thisCommand.CommandText = "SELECT PUNCHDTM FROM PERSON AS PS JOIN PUNCHEVENT AS PE on PS.PERSONID = PE.EMPLOYEEID inner join DATASOURCE as DS on PE.DATASOURCEID = DS.DATASOURCEID WHERE PUNCHDTM > '" + Start + "' AND PUNCHDTM < '" + End + "' AND PE.DELETEDSW = 0 AND PS.PERSONNUM = '" + ADPId + "' order by PUNCHDTM ASC";
            SqlDataReader thisReader;
            thisReader = thisCommand.ExecuteReader();
            while (thisReader.Read())
            {
                Times.Add(thisReader["PUNCHDTM"].ToString());
            }
            string ClockIn = "";
            foreach (string TempTime in Times)
            {
                if (ClockIn == "")
                {
                    ClockIn = TempTime;
                }
                else
                {
                    double ClockTime = ((Convert.ToDateTime(TempTime) - Convert.ToDateTime(ClockIn)).TotalSeconds);

                    ADPTime +=  Convert.ToInt32(ClockTime);
                    ClockIn = "";

                }
            }
            thisReader.Close();
            thisConnection.Close();
            return ADPTime; <---------This is where I get other error

        }
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Weird VS and C# issue

Post by Jackolantern »

GetADPTime is setup to return a string. I think it is just VS complaining that you are trying to return the results of a method setup to return a string to an int variable without parsing. Can you just change the signature of GetADPTime?
The indelible lord of tl;dr
Sim
Posts: 412
Joined: Sat Dec 26, 2009 5:37 pm

Re: Weird VS and C# issue

Post by Sim »

Cast it? ;\
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Weird VS and C# issue

Post by hallsofvallhalla »

sorry forgot about this thread, I forgot to change it back when posting this but I normally do have it as an int and it still complains. The problem went away on its own after a restart of the PC and re open and rebuild of the project.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: Weird VS and C# issue

Post by Jackolantern »

VS probably just didn't update the metadata from the last build where it was a string I suppose. I have had stuff like this before. In fact, I have had pretty much the whole thing blow up, where it suddenly flags everything as being a syntax error and more. Just closed and re-opened and it worked fine lol.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Weird VS and C# issue

Post by hallsofvallhalla »

ha, had a few of those before but like you said a close or even a rebuild would fix it. This however never fixed until a restart. Oh well it is fixed now. VS is still the best IDE known to man imho
Post Reply

Return to “Beginner Help and Support”