System.Argument Exception
-
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
-
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
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 – ∞)
-
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 – ∞)
Sorry, I missed that on my cut and paste. The close bracket is there.
Jude
-
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
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
-
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
Ver 3.5.1, Runtime ver 2.0.50727 Message=System.ArgumentException: Date
Jude
-
Ver 3.5.1, Runtime ver 2.0.50727 Message=System.ArgumentException: Date
Jude
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.
-
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
Are you sure that dtPD is a DateTime? Or is it rather a DateTimePicker? Or a string conatining a formatted datetime value?
-
Sorry, I missed that on my cut and paste. The close bracket is there.
Jude
-
Ver 3.5.1, Runtime ver 2.0.50727 Message=System.ArgumentException: Date
Jude
Are you sure you're passing
SqlDbType.DateTime
to theParameters.Add
method, and notSqlDbType.Date
? The only place I can see that would throw anArgumentException
with a message of "Date" is if you're passing an unsupportedSqlDbType
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