Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. if someone could help me identify the problem please. [modified]

if someone could help me identify the problem please. [modified]

Scheduled Pinned Locked Moved C#
helpdatabasewpf
14 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D DinoRondelly

    Here is my Code

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.Data.Odbc;
    using My;
    using System.Data;

    namespace FirstCitizensBank_DropOffReport
    {
    class Program : MyGeneral
    {
    public static string dataBasePath;
    public static string dbname;
    public static string strconn;
    static void Main(string[] args)
    {
    StartUp("", "", true);
    dataBasePath = ConfigPath + "Empathic\\FirstCit\\";
    dbname = "Bank";
    strconn = "";

            try
            {
                string repname = dataBasePath + "Reports\\\\Dropoff" + myDate.ToString("yyyyMMdd") + ".xls";
    
                DateTime enddate = myDate.AddDays(-myDate.Day);
                DateTime startdate = enddate.AddDays(1).AddMonths(-1);
                MyWriteExcel exl = new MyWriteExcel(repname, dataBasePath + "Reports\\\\Templates\\\\DropoffTemp.xls");
    
                //dbname = dbname + myDate.ToString("yyMM");
                //WriteMonth(ref exl, startdate, enddate, "B");
    
                enddate = startdate.AddDays(-1);
                //startdate = startdate.AddMonths(-1);
                dbname = "Bank";
                dbname = dbname + myDate.AddMonths(-1).ToString("yyMM");
                WriteMonth(ref exl, startdate, enddate, "C");
    
                enddate = startdate.AddDays(-1);
                startdate = startdate.AddMonths(-2);
                dbname = "Bank";
                dbname = dbname + myDate.AddMonths(-2).ToString("yyMM");
                WriteMonth(ref exl, startdate, enddate, "D");
    
                exl.Save();
                exl.Close();
    
                MyEmail email = new MyEmail("", "First Citizens Bank Dropoff Report", "Please see attached report");
                email.AddAttachment(repname);
                email.AddBCC(CommonEmail);
                email.sendEmail();
    
                endProgram();
            }
            catch (Exception e)
            {
                WriteToLog("@Failed: " + e.ToString());
    
                HelpPage(e.ToString(), "Failed");
            }
    
        }
    
        public static void WriteMonth(ref MyWriteExcel exl, DateTime startdate, DateTime enddate, string column)
        {
            string sql = "select count(\*) as total, sum(iif(mid(CALLSTATUS, 1, 2) >= '06', 1, 0)) as entered, sum(iif(DONE is not null, 1, 0)) as completed"
                    + " from " + dbname + " where startdate
    
    N Offline
    N Offline
    Nagy Vilmos
    wrote on last edited by
    #2

    whwen comparing two strings, you should use the

    s1.Equals(s2)

    . The code s1 == s2 just returns true if they are the same object not the same value.


    Panic, Chaos, Destruction. My work here is done.

    P L A 4 Replies Last reply
    0
    • N Nagy Vilmos

      whwen comparing two strings, you should use the

      s1.Equals(s2)

      . The code s1 == s2 just returns true if they are the same object not the same value.


      Panic, Chaos, Destruction. My work here is done.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #3

      Where does it say that? Do you have proof? Why do people still believe this? :wtf: P.S. See: http://msdn.microsoft.com/en-us/library/system.string.op_equality(VS.71).aspx[^] " This operator is implemented using the Equals method, which means the comparands are tested for a combination of reference and value equality. The comparison is case-sensitive. " Therefore == == Equals !

      N L 2 Replies Last reply
      0
      • N Nagy Vilmos

        whwen comparing two strings, you should use the

        s1.Equals(s2)

        . The code s1 == s2 just returns true if they are the same object not the same value.


        Panic, Chaos, Destruction. My work here is done.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #4

        Aren't all strings "interned" in .NET, i.e. two strings holding the same value actually point to a single instance? [EDIT] No, they are not (see this little article[^]). However, string1==string2 and string.Equals(string1,string2) both call the string.Equals method and generate the correct result no matter what. [/EDIT] :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        modified on Friday, September 4, 2009 1:02 PM

        N C 2 Replies Last reply
        0
        • P PIEBALDconsult

          Where does it say that? Do you have proof? Why do people still believe this? :wtf: P.S. See: http://msdn.microsoft.com/en-us/library/system.string.op_equality(VS.71).aspx[^] " This operator is implemented using the Equals method, which means the comparands are tested for a combination of reference and value equality. The comparison is case-sensitive. " Therefore == == Equals !

          N Offline
          N Offline
          Nagy Vilmos
          wrote on last edited by
          #5

          I was sure that it was the case. I have just chickened and according to Troelsen, == and .equals both compare content. :-O I think it's wrong, but going by what Luc says below it makes some sort of sense. I have java as well as C#, there it is absolutly == comnpares references and .equals() compares values.


          Panic, Chaos, Destruction. My work here is done.

          P 1 Reply Last reply
          0
          • L Luc Pattyn

            Aren't all strings "interned" in .NET, i.e. two strings holding the same value actually point to a single instance? [EDIT] No, they are not (see this little article[^]). However, string1==string2 and string.Equals(string1,string2) both call the string.Equals method and generate the correct result no matter what. [/EDIT] :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


            modified on Friday, September 4, 2009 1:02 PM

            N Offline
            N Offline
            Nagy Vilmos
            wrote on last edited by
            #6

            head is bowed.


            Panic, Chaos, Destruction. My work here is done.

            1 Reply Last reply
            0
            • N Nagy Vilmos

              I was sure that it was the case. I have just chickened and according to Troelsen, == and .equals both compare content. :-O I think it's wrong, but going by what Luc says below it makes some sort of sense. I have java as well as C#, there it is absolutly == comnpares references and .equals() compares values.


              Panic, Chaos, Destruction. My work here is done.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #7

              Well .net is better than Java. (duh!) :-D

              1 Reply Last reply
              0
              • D DinoRondelly

                Here is my Code

                using System;
                using System.Collections.Generic;
                using System.Text;
                using System.IO;
                using System.Data.Odbc;
                using My;
                using System.Data;

                namespace FirstCitizensBank_DropOffReport
                {
                class Program : MyGeneral
                {
                public static string dataBasePath;
                public static string dbname;
                public static string strconn;
                static void Main(string[] args)
                {
                StartUp("", "", true);
                dataBasePath = ConfigPath + "Empathic\\FirstCit\\";
                dbname = "Bank";
                strconn = "";

                        try
                        {
                            string repname = dataBasePath + "Reports\\\\Dropoff" + myDate.ToString("yyyyMMdd") + ".xls";
                
                            DateTime enddate = myDate.AddDays(-myDate.Day);
                            DateTime startdate = enddate.AddDays(1).AddMonths(-1);
                            MyWriteExcel exl = new MyWriteExcel(repname, dataBasePath + "Reports\\\\Templates\\\\DropoffTemp.xls");
                
                            //dbname = dbname + myDate.ToString("yyMM");
                            //WriteMonth(ref exl, startdate, enddate, "B");
                
                            enddate = startdate.AddDays(-1);
                            //startdate = startdate.AddMonths(-1);
                            dbname = "Bank";
                            dbname = dbname + myDate.AddMonths(-1).ToString("yyMM");
                            WriteMonth(ref exl, startdate, enddate, "C");
                
                            enddate = startdate.AddDays(-1);
                            startdate = startdate.AddMonths(-2);
                            dbname = "Bank";
                            dbname = dbname + myDate.AddMonths(-2).ToString("yyMM");
                            WriteMonth(ref exl, startdate, enddate, "D");
                
                            exl.Save();
                            exl.Close();
                
                            MyEmail email = new MyEmail("", "First Citizens Bank Dropoff Report", "Please see attached report");
                            email.AddAttachment(repname);
                            email.AddBCC(CommonEmail);
                            email.sendEmail();
                
                            endProgram();
                        }
                        catch (Exception e)
                        {
                            WriteToLog("@Failed: " + e.ToString());
                
                            HelpPage(e.ToString(), "Failed");
                        }
                
                    }
                
                    public static void WriteMonth(ref MyWriteExcel exl, DateTime startdate, DateTime enddate, string column)
                    {
                        string sql = "select count(\*) as total, sum(iif(mid(CALLSTATUS, 1, 2) >= '06', 1, 0)) as entered, sum(iif(DONE is not null, 1, 0)) as completed"
                                + " from " + dbname + " where startdate
                
                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #8

                Dunno, step through it with the debugger and see what's actually happening.

                1 Reply Last reply
                0
                • N Nagy Vilmos

                  whwen comparing two strings, you should use the

                  s1.Equals(s2)

                  . The code s1 == s2 just returns true if they are the same object not the same value.


                  Panic, Chaos, Destruction. My work here is done.

                  A Offline
                  A Offline
                  Adam R Harris
                  wrote on last edited by
                  #9

                  Ummm .... they both work. Case in point;

                      static void Main(string\[\] args)
                      {
                          string strTest1 = "This is a test";
                          string strTest2 = "This is a second test";
                  
                          Console.WriteLine("strTest1 == strTest2 : {0}", strTest1 == strTest2);
                          Console.WriteLine("strTest1 == \\"This is a test\\" : {0}", strTest1 == "This is a test");
                          Console.WriteLine("strTest1.Equals(strTest2) : {0}", strTest1.Equals(strTest2));
                          Console.WriteLine("strTest1.Equals(\\"This is a test\\") : {0}", strTest1.Equals("This is a test"));
                          Console.ReadLine();
                     }
                  

                  output

                  strTest1 == strTest2 : False
                  strTest1 == "This is a test" : True
                  strTest1.Equals(strTest2) : False
                  strTest1.Equals("This is a test") : True

                  If at first you don't succeed ... post it on The Code Project and Pray.

                  1 Reply Last reply
                  0
                  • D DinoRondelly

                    Here is my Code

                    using System;
                    using System.Collections.Generic;
                    using System.Text;
                    using System.IO;
                    using System.Data.Odbc;
                    using My;
                    using System.Data;

                    namespace FirstCitizensBank_DropOffReport
                    {
                    class Program : MyGeneral
                    {
                    public static string dataBasePath;
                    public static string dbname;
                    public static string strconn;
                    static void Main(string[] args)
                    {
                    StartUp("", "", true);
                    dataBasePath = ConfigPath + "Empathic\\FirstCit\\";
                    dbname = "Bank";
                    strconn = "";

                            try
                            {
                                string repname = dataBasePath + "Reports\\\\Dropoff" + myDate.ToString("yyyyMMdd") + ".xls";
                    
                                DateTime enddate = myDate.AddDays(-myDate.Day);
                                DateTime startdate = enddate.AddDays(1).AddMonths(-1);
                                MyWriteExcel exl = new MyWriteExcel(repname, dataBasePath + "Reports\\\\Templates\\\\DropoffTemp.xls");
                    
                                //dbname = dbname + myDate.ToString("yyMM");
                                //WriteMonth(ref exl, startdate, enddate, "B");
                    
                                enddate = startdate.AddDays(-1);
                                //startdate = startdate.AddMonths(-1);
                                dbname = "Bank";
                                dbname = dbname + myDate.AddMonths(-1).ToString("yyMM");
                                WriteMonth(ref exl, startdate, enddate, "C");
                    
                                enddate = startdate.AddDays(-1);
                                startdate = startdate.AddMonths(-2);
                                dbname = "Bank";
                                dbname = dbname + myDate.AddMonths(-2).ToString("yyMM");
                                WriteMonth(ref exl, startdate, enddate, "D");
                    
                                exl.Save();
                                exl.Close();
                    
                                MyEmail email = new MyEmail("", "First Citizens Bank Dropoff Report", "Please see attached report");
                                email.AddAttachment(repname);
                                email.AddBCC(CommonEmail);
                                email.sendEmail();
                    
                                endProgram();
                            }
                            catch (Exception e)
                            {
                                WriteToLog("@Failed: " + e.ToString());
                    
                                HelpPage(e.ToString(), "Failed");
                            }
                    
                        }
                    
                        public static void WriteMonth(ref MyWriteExcel exl, DateTime startdate, DateTime enddate, string column)
                        {
                            string sql = "select count(\*) as total, sum(iif(mid(CALLSTATUS, 1, 2) >= '06', 1, 0)) as entered, sum(iif(DONE is not null, 1, 0)) as completed"
                                    + " from " + dbname + " where startdate
                    
                    D Offline
                    D Offline
                    DinoRondelly
                    wrote on last edited by
                    #10

                    I have solved this problem and appreciate all the reply's. The problem was that if a call status came back that wasn't in one of my if statements the program was defaulting to the last line number used since i am not increamenting line numbers. I am sure this is a rookie mistake and i thank you.

                    P 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Where does it say that? Do you have proof? Why do people still believe this? :wtf: P.S. See: http://msdn.microsoft.com/en-us/library/system.string.op_equality(VS.71).aspx[^] " This operator is implemented using the Equals method, which means the comparands are tested for a combination of reference and value equality. The comparison is case-sensitive. " Therefore == == Equals !

                      L Offline
                      L Offline
                      LetMeFinclOut
                      wrote on last edited by
                      #11

                      PIEBALDconsult wrote:

                      Therefore == == Equals !

                      :cool:

                      1 Reply Last reply
                      0
                      • D DinoRondelly

                        I have solved this problem and appreciate all the reply's. The problem was that if a call status came back that wasn't in one of my if statements the program was defaulting to the last line number used since i am not increamenting line numbers. I am sure this is a rookie mistake and i thank you.

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #12

                        Yeah, see? Use a switch instead.

                        1 Reply Last reply
                        0
                        • L Luc Pattyn

                          Aren't all strings "interned" in .NET, i.e. two strings holding the same value actually point to a single instance? [EDIT] No, they are not (see this little article[^]). However, string1==string2 and string.Equals(string1,string2) both call the string.Equals method and generate the correct result no matter what. [/EDIT] :)

                          Luc Pattyn [Forum Guidelines] [My Articles]


                          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


                          modified on Friday, September 4, 2009 1:02 PM

                          C Offline
                          C Offline
                          Curtis Schlak
                          wrote on last edited by
                          #13

                          Depending on your point of view, fortunately or unfortunately, not all strings in the CLI are interned. Essentially, any string loaded with the MSIL ldstr command is interned, and anything programatically interned is interned. For example, if we run the following code

                          string interned1 = "hello";
                          string interned2 = "hello";
                          string notinterned = new String("hello".ToCharArray());
                          string interned4 = string.Intern(notinterned);
                          Console.WriteLine(RuntimeHelpers.GetHashCode(interned1));
                          Console.WriteLine(RuntimeHelpers.GetHashCode(interned2));
                          Console.WriteLine(RuntimeHelpers.GetHashCode(notinterned));
                          Console.WriteLine(RuntimeHelpers.GetHashCode(interned4));

                          then we get the corresponding output

                          58225482
                          58225482
                          54267293
                          58225482

                          As you can see from the output, the interned strings all show the same "memory location" while the programatically constructed string shows a different location. (.NET 3.5) In terms of string equality, though, the override of operator== calls the public static string.Equals(string, string) method which calls a private static method to determine equality. string.Equals(string) calls the private static method directly.

                          "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                          1 Reply Last reply
                          0
                          • N Nagy Vilmos

                            whwen comparing two strings, you should use the

                            s1.Equals(s2)

                            . The code s1 == s2 just returns true if they are the same object not the same value.


                            Panic, Chaos, Destruction. My work here is done.

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #14

                            Hi Nagy,

                            Nagy Vilmos wrote:

                            s1 == s2 just returns true if they are the same object

                            as others already told you, this is completely wrong. I did some investigation, triggered both by this thread and by the lean-and-mean competition, and that resulted in this little article of mine[^]. :)

                            Luc Pattyn

                            :badger: :jig: :badger:

                            Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.

                            :jig: :badger: :jig:

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups