none
An improbable compile error for OleDb.Date type RRS feed

  • Question

  • In the function below I get an error that System.Data.OleDb namespace does not contain the type Date. The error occurs in the function header only. When the same type is used in the parameters definition the same type is accepted all right. It has actually worked for many months for me. I am attempting to consolidate the code into one function and this is how it happens.

     

    ERROR message:

     

    The type name 'Date' does not exist in the type 'System.Data.DbType'

     

    I can even see it in the IntelliSense dropdown menu.

     

    public static OleDbCommand createOleDbParameter ( OleDbCommand cmdm, string parName,

    System.Data.DbType.Date parValue )  // <== compile error here.

    { // overload: type Date

    OleDbParameter par2 = cmdm.CreateParameter ( );

    par2.SourceVersion = DataRowVersion.Proposed;

    par2.ParameterName = parName;

    par2.DbType = DbType.Date;  // < NO PROBLEM, worked for months

    par2.Direction = ParameterDirection.InputOutput;

    par2.SourceColumn = parName;

    par2.Value = parValue;

    cmdm.Parameters.Add ( par2 );

    }

     

    Am I going nuts or what?

     

    Thanks.

    Tuesday, March 25, 2008 7:30 PM

All replies

  • What error are you getting? In your explanation you said you get this error:

    System.Data.OleDb namespace does not contain the type Date

    A bit further you write that you get this error:

    The type name 'Date' does not exist in the type 'System.Data.DbType'

    Also, the parameter specifies a fully qualified type name (including namespace), but the assignment does not, so it's not the same. Without knowing what using statements you specified, and the namespace and class name this method is defined in, there's no way of knowing for sure what the problem is...

    Tuesday, March 25, 2008 8:00 PM
  •  Philippe Leybaert wrote:
    What error are you getting? In your explanation you said you get this error:

    System.Data.OleDb namespace does not contain the type Date

    A bit further you write that you get this error:

    The type name 'Date' does not exist in the type 'System.Data.DbType'

    Also, the parameter specifies a fully qualified type name (including namespace), but the assignment does not, so it's not the same. Without knowing what using statements you specified, and the namespace and class name this method is defined in, there's no way of knowing for sure what the problem is...

     

    You may disregard this.

    System.Data.OleDb namespace does not contain the type Date

    I thought that the statements I provided (first was my verbal interpretation, the other was the error message I COPIED from the debugger's Error window) were equaivalent.

     

    As far as the second part of your question:

     

    Also, the parameter specifies a fully qualified type name (including namespace), but the assignment does not, so it's not the same

     

    They are the same. I actually did not have the namespace included in the parameter list at first and I got this error. The parameter type was exactly the same as in the statement below (it did not include namespace): OleDbType.Date, that's it. Adding a namespace qualifier does not change anything. The statements THE SAME.

    Tuesday, March 25, 2008 9:44 PM
  • I don't quite understand. Now you're talking about "OleDbType.Date", but your first post mentioned "DbType.Date".

     

    OleDbType and DbType are located in different namespaces, so that can cause the error you're describing. Please provide a real code example (including the namespace declaration and the using statements).

     

     

    Tuesday, March 25, 2008 9:47 PM
  • OleDbType and DbType are enumerations, where as OleDbType.Date and DbType.Date are values in there respective enumerations.   In the method declaration it it looking for the type, which would be simply OleDbType or DbType.  From your code, it would appear that parValue should be some type of object that represents a date, perhaps a DateTime object?

     

    Code Snippet

    public static OleDbCommand createOleDbParameter ( OleDbCommand cmdm, string parNameDateTime parValue ) 

     

     

    Hope this help.
    Wednesday, March 26, 2008 1:54 AM
  •  veryed wrote:

    OleDbType and DbType are enumerations, where as OleDbType.Date and DbType.Date are values in there respective enumerations.   In the method declaration it it looking for the type, which would be simply OleDbType or DbType.  From your code, it would appear that parValue should be some type of object that represents a date, perhaps a DateTime object?

     

    Code Snippet

    public static OleDbCommand createOleDbParameter ( OleDbCommand cmdm, string parNameDateTime parValue ) 

     

     

    Hope this help.

     

    OK, this is the scoop. I am kind of tired at the end of the day so may goof up some.

     

    I am storing some data in Visual Fox Pro 9 databases. I've been doing it for months and months, actually years. VFP has DateTime and Date formats separately typed. I use Date format (not DateTime). In C# code I get rid of the time component of DateTime and set this variable as a parameter value (DateTime.Now.Date) to send down the Connection. I use the DbType.Date type. it works fine when I type the parameter itself. However, when I tried to consolidate this code into a stand alone procedure (I have numerous places where the same set of redundant statements is used) I got in trouble because in the PARAMATER LIST of the procedure this type (DbType.Date unexpectedly caused an error. 

     

    If I typed the values as DateTime I would have gotten an error from DBE because it expects a different type for the column.

    Wednesday, March 26, 2008 2:10 AM
  • I was just suggesting DateTime since I didn't know what actual type you were passing.  What I am say is that DbType.Date is not a type but a value of an enumeration and therefore cannot be used in a method declaration as a Type.  You have to pass in the object type that you want to store (Date, DateTime, Object, whatever).

     

    Code Snippet
    public static OleDbCommand createOleDbParameter ( OleDbCommand cmdm, string parName, <YourTypeHere> parValue ) 

     

     

    You may try just using "object" as the type and see what happens since value just takes any old object.  If the object you pass in to the method is the correct type, at its core, for the database then everything should work just fine. 

     

    Once again, the reason you would see:

     

    The type name 'Date' does not exist in the type 'System.Data.DbType'

     

    is because, System.Data.DbType.Date is NOT a type.  It is a value of the System.Data.DbType enumeration.

    Wednesday, March 26, 2008 2:32 AM
  • Alex, this seems to be a very trivial and easy to fix problem, but please post the real code snippet, the namespace declaration where the code snippet is declared and the using statements.

     

    We could go on forever guessing.

     

    Wednesday, March 26, 2008 8:35 AM
  •  veryed wrote:

    OleDbType and DbType are enumerations, where as OleDbType.Date and DbType.Date are values in there respective enumerations.   In the method declaration it it looking for the type, which would be simply OleDbType or DbType.  From your code, it would appear that parValue should be some type of object that represents a date, perhaps a DateTime object?

     

    Code Snippet

    public static OleDbCommand createOleDbParameter ( OleDbCommand cmdm, string parNameDateTime parValue ) 

     

     

    Hope this help.

     

    Yep, of course you are right. It is amazing I did not see the light yesterday and got mired and confused in trivialities. Sure I have to type the DateType variable in the fucntionc call as DateTime.

     

    Your contribution has been recognized as decisive in clearing my mindSmile

     

    Thanks a lot to everyone else who posted.

    Wednesday, March 26, 2008 12:52 PM