Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
TimeIn = New DateTime <<------ What should i change here??

try

 

TimeIn = null

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*
Posted

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.

Posted

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

Posted
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.

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.

Posted
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

 

 

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.

Posted
Thanks for help, it works

 

 

Calvin :D

here to serve. . . and gripe about VB

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...