calvin Posted August 20, 2004 Posted August 20, 2004 I want to update a Date/Time datatype in MS Access by Null value(or blank?). A variable is declare as DateTime datatype in ASP.NET. I was use the following approach try to set null/empty. Dim TimeIn as DateTime TimeIn = New DateTime <<------ What should i change here?? :confused: 'Update Statement here' ... ... cmdUpdate.Parameters.Add("@TimeIn", TimeIn) ... After update the DB, all the column which store TimeIn contain a value 01-01-2001, this is not what i want. I want it is "Totally nothing(null/empty)" in the column. When I bind the TimeIn to the datagrid, it will show "12:00:00 AM " Is anyone know to solve it.Thank you Calvin Quote
Joe Mamma Posted August 20, 2004 Posted August 20, 2004 TimeIn = New DateTime <<------ What should i change here?? try TimeIn = null Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
*Gurus* Derek Stone Posted August 20, 2004 *Gurus* Posted August 20, 2004 Value types can't be null. You need to do something like this: Dim birthdate As DateTime = DateTime.MaxValue If birthdate = DateTime.MaxValue Then cmdUpdate.Parameters.Add("@TimeIn", Nothing) End If Then again I don't recommend allowing null values into your database, but that's a whole 'nother bag of beans. Quote Posting Guidelines
calvin Posted August 23, 2004 Author Posted August 23, 2004 I get this error: Parameter 0: '@TimeIn', the property DbType is uninitialized: OleDbType.Empty. I think we can't use "Nothing" add to table Calvin Quote
Joe Mamma Posted August 23, 2004 Posted August 23, 2004 Then again I don't recommend allowing null values into your database huh??? the concept of null is critical!!!! I use it all the time and depend on it for the relational model. not always but it is often called for and when it is, I accept it. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted August 23, 2004 Posted August 23, 2004 try TimeIn = null sorry about this (what was that about testing code before posting PD???) you want to do this. . . [size=2]Dim [/size][size=2]oTimeIn as = object = System.DBNull.Value[/size] ' do something to possibly set oTimeIn to an actual date value. . . ' and set up your update statement ' then . . . cmdUpdate.Parameters.Add(new OleDbParameter("@TimeIn", TimeIn)) cmdUpdate.ExecuteNonScalar forget about the spaghetti approach: if test then this else that end if bad. . very bad Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
calvin Posted August 27, 2004 Author Posted August 27, 2004 Thanks for help, it works Calvin :D Quote
Joe Mamma Posted August 27, 2004 Posted August 27, 2004 Thanks for help, it works Calvin :D here to serve. . . and gripe about VB Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.