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. System.Argument Exception

System.Argument Exception

Scheduled Pinned Locked Moved C#
databasevisual-studioquestion
9 Posts 6 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.
  • T Offline
    T Offline
    TheJudeDude
    wrote on last edited by
    #1

    I am attempting to rewrite a program using SqlCE database vs an OleDb database. The code below worked using OleDb, but now throws a System.Argument exception.

    SqlCeCommand GetAcctsCmd = new SqlCeCommand("SELECT ACCTSTORE, ACCTMGR, Count(ACCTMGR) AS [CountOfACCTMGR] FROM ALLACCOUNTS WHERE (DATEDIFF(d, ACCTNEXTDUE, @TESTDATE) > 0 )";
    GetAcctsCmd.Parameters.Add("@TESTDATE", SqlDbType.DateTime);
    GetAcctsCmd.Parameters["@TESTDATE"].Value = dtPD;

    The exception is being thrown on the last line of code above. dtPD is a DateTime. What am I missing? Thanks in advance.

    Jude

    OriginalGriffO Richard DeemingR B 3 Replies Last reply
    0
    • T TheJudeDude

      I am attempting to rewrite a program using SqlCE database vs an OleDb database. The code below worked using OleDb, but now throws a System.Argument exception.

      SqlCeCommand GetAcctsCmd = new SqlCeCommand("SELECT ACCTSTORE, ACCTMGR, Count(ACCTMGR) AS [CountOfACCTMGR] FROM ALLACCOUNTS WHERE (DATEDIFF(d, ACCTNEXTDUE, @TESTDATE) > 0 )";
      GetAcctsCmd.Parameters.Add("@TESTDATE", SqlDbType.DateTime);
      GetAcctsCmd.Parameters["@TESTDATE"].Value = dtPD;

      The exception is being thrown on the last line of code above. dtPD is a DateTime. What am I missing? Thanks in advance.

      Jude

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      A close bracket...

      SqlCeCommand GetAcctsCmd = new SqlCeCommand("SELECT ACCTSTORE, ACCTMGR, Count(ACCTMGR) AS [CountOfACCTMGR] FROM ALLACCOUNTS WHERE DATEDIFF(d, ACCTNEXTDUE, @TESTDATE) > 0 ");

      Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      T 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        A close bracket...

        SqlCeCommand GetAcctsCmd = new SqlCeCommand("SELECT ACCTSTORE, ACCTMGR, Count(ACCTMGR) AS [CountOfACCTMGR] FROM ALLACCOUNTS WHERE DATEDIFF(d, ACCTNEXTDUE, @TESTDATE) > 0 ");

        Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

        T Offline
        T Offline
        TheJudeDude
        wrote on last edited by
        #3

        Sorry, I missed that on my cut and paste. The close bracket is there.

        Jude

        P 1 Reply Last reply
        0
        • T TheJudeDude

          I am attempting to rewrite a program using SqlCE database vs an OleDb database. The code below worked using OleDb, but now throws a System.Argument exception.

          SqlCeCommand GetAcctsCmd = new SqlCeCommand("SELECT ACCTSTORE, ACCTMGR, Count(ACCTMGR) AS [CountOfACCTMGR] FROM ALLACCOUNTS WHERE (DATEDIFF(d, ACCTNEXTDUE, @TESTDATE) > 0 )";
          GetAcctsCmd.Parameters.Add("@TESTDATE", SqlDbType.DateTime);
          GetAcctsCmd.Parameters["@TESTDATE"].Value = dtPD;

          The exception is being thrown on the last line of code above. dtPD is a DateTime. What am I missing? Thanks in advance.

          Jude

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          What version of the SqlCE libraries are you using, and what's the exception message?


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          T 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            What version of the SqlCE libraries are you using, and what's the exception message?


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            T Offline
            T Offline
            TheJudeDude
            wrote on last edited by
            #5

            Ver 3.5.1, Runtime ver 2.0.50727 Message=System.ArgumentException: Date

            Jude

            Richard Andrew x64R Richard DeemingR 2 Replies Last reply
            0
            • T TheJudeDude

              Ver 3.5.1, Runtime ver 2.0.50727 Message=System.ArgumentException: Date

              Jude

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #6

              Isn't there also a message description that tells details? I've never seen an exception that just says "Date".

              The difficult we do right away... ...the impossible takes slightly longer.

              1 Reply Last reply
              0
              • T TheJudeDude

                I am attempting to rewrite a program using SqlCE database vs an OleDb database. The code below worked using OleDb, but now throws a System.Argument exception.

                SqlCeCommand GetAcctsCmd = new SqlCeCommand("SELECT ACCTSTORE, ACCTMGR, Count(ACCTMGR) AS [CountOfACCTMGR] FROM ALLACCOUNTS WHERE (DATEDIFF(d, ACCTNEXTDUE, @TESTDATE) > 0 )";
                GetAcctsCmd.Parameters.Add("@TESTDATE", SqlDbType.DateTime);
                GetAcctsCmd.Parameters["@TESTDATE"].Value = dtPD;

                The exception is being thrown on the last line of code above. dtPD is a DateTime. What am I missing? Thanks in advance.

                Jude

                B Offline
                B Offline
                Bernhard Hiller
                wrote on last edited by
                #7

                Are you sure that dtPD is a DateTime? Or is it rather a DateTimePicker? Or a string conatining a formatted datetime value?

                1 Reply Last reply
                0
                • T TheJudeDude

                  Sorry, I missed that on my cut and paste. The close bracket is there.

                  Jude

                  P Offline
                  P Offline
                  phil o
                  wrote on last edited by
                  #8

                  I would be curious to know your copy & paste technic, then :)

                  while (!working) {
                  Reboot();
                  }

                  1 Reply Last reply
                  0
                  • T TheJudeDude

                    Ver 3.5.1, Runtime ver 2.0.50727 Message=System.ArgumentException: Date

                    Jude

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #9

                    Are you sure you're passing SqlDbType.DateTime to the Parameters.Add method, and not SqlDbType.Date? The only place I can see that would throw an ArgumentException with a message of "Date" is if you're passing an unsupported SqlDbType value in:

                    internal static SqlCeType FromSqlDbType(SqlDbType type)
                    {
                    for (int index = 0; index < SqlCeType._AllTypes.Length; ++index)
                    {
                    if (type == SqlCeType._AllTypes[index].SqlDbType)
                    return SqlCeType._AllTypes[index];
                    }

                    throw new ArgumentException(type.ToString());
                    

                    }

                    This error message has been improved in v4 of the SqlServerCe library. If that's not the problem, can you post the stack-trace of the exception?


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    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