Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Hi, I'm having trouble getting an Access database to read a DateTime... when I call System.DateTime.Now, and store the result of that into a table and Update... going into my database, I notice that it stores only the date, but not the time. It reads the time as 12:00 AM, which I'm pretty sure means the same thing as just reading the date. Is there something I'm overlooking? I'm using Microsoft Jet 4.0 OLE DB provider; I'm pretty sure that's the proper OleDB Connection to use... please help.
Still getting my head around this ADO stuff... sigh.
Posted
At run time, DateTime.Now is returning the time. I can also confirm that when I load that into my DataSet, the time information is still retained. It is when I execute Update that the time information is lost.
Still getting my head around this ADO stuff... sigh.
Posted
Hmm. In that case, can you show us the code you use for your Update command? (if unable because of security reasons then provide us with a sample that includes dumbied values)
Gamer extraordinaire. Programmer wannabe.
Posted
I fixed the problem by switching to an ODBC connection. Odd that Jet 4.0 would mess up, but eh. If anyone wants to figure out why this happened, I'd appreciate it.
Still getting my head around this ADO stuff... sigh.
Posted

Actually, ODBC is being just awful with its update command. So I'd like to switch back to Jet 4.0. Below is the code for my Update Command.

 

Me.OleDbUpdateCommand1.CommandText = "UPDATE tblShortLongBikeNames SET DateShortened = ?, DateUnshortened = ?, LongName" & _

" = ?, UnshortenedYesNo = ? WHERE (ShortName = ?) AND (DateShortened = ? OR ? IS " & _

"NULL AND DateShortened IS NULL) AND (DateUnshortened = ? OR ? IS NULL AND DateUn" & _

"shortened IS NULL) AND (LongName = ? OR ? IS NULL AND LongName IS NULL) AND (Uns" & _

"hortenedYesNo = ?)"

Me.OleDbUpdateCommand1.Connection = Me.OleDbConnection1

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("DateShortened", System.Data.OleDb.OleDbType.DBDate, 0, "DateShortened"))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("DateUnshortened", System.Data.OleDb.OleDbType.DBDate, 0, "DateUnshortened"))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("LongName", System.Data.OleDb.OleDbType.VarWChar, 100, "LongName"))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("UnshortenedYesNo", System.Data.OleDb.OleDbType.Boolean, 2, "UnshortenedYesNo"))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_ShortName", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ShortName", System.Data.DataRowVersion.Original, Nothing))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_DateShortened", System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "DateShortened", System.Data.DataRowVersion.Original, Nothing))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_DateShortened1", System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "DateShortened", System.Data.DataRowVersion.Original, Nothing))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_DateUnshortened", System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "DateUnshortened", System.Data.DataRowVersion.Original, Nothing))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_DateUnshortened1", System.Data.OleDb.OleDbType.DBDate, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "DateUnshortened", System.Data.DataRowVersion.Original, Nothing))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_LongName", System.Data.OleDb.OleDbType.VarWChar, 100, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "LongName", System.Data.DataRowVersion.Original, Nothing))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_LongName1", System.Data.OleDb.OleDbType.VarWChar, 100, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "LongName", System.Data.DataRowVersion.Original, Nothing))

Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_UnshortenedYesNo", System.Data.OleDb.OleDbType.Boolean, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "UnshortenedYesNo", System.Data.DataRowVersion.Original, Nothing))

Still getting my head around this ADO stuff... sigh.
Posted (edited)

I noticed that DBDate won't transmit the time, so I want to switch it to a DBTimeStamp. But when I replace every occurence of DBDate with DBTimeStamp, It throws this:

 

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

 

I don't think I can change my Access database to handle this, I can only set a field as a Date/Time.

Edited by Thoth
Still getting my head around this ADO stuff... sigh.
Posted
I know what you mean, and I am using a Date/Time column in Access. However, instead of updating the data with a type System.Data.OleDb.OleDbType.DBDate, I use a System.Data.OleDb.OleDbType.DBTimeStamp, because DBDate only transmits yyyymmdd, and TimeStamp does yyyymmddhhmmss and I need those hours, minutes, and seconds.
Still getting my head around this ADO stuff... sigh.
Posted

For clarification's sake, this is part of the OleDbType Enumeration:

 

DBTimeStamp: Data and time data in the format yyyymmddhhmmss (DBTYPE_DBTIMESTAMP). This maps to DateTime.

 

Basically, my question is this: If I want to change DBDate to DBTimeStamp, what else do I need to change besides my Update, Insert, and Delete statements?

Still getting my head around this ADO stuff... sigh.
Posted

Hmm.. I'm afraid perhaps I'm confusing the issue. I use SQL Server and assumed that SqlDbType was similar to OleDbType. I guess not. In SqlDbType there's a DateTime, why OleDbType doesn't offer this just baffles me.

 

But now your problem at least makes sense. The reason it didn't store the time is because the OleDbType.DBDate only stores the date (no times).

 

Ergh.. anyway. I would try something like "#?#" in your command text, then use the parameter as a string to pass in the date and time, or forget the parameter mess altogether and just build the string dynamically. At the very least I'd go back to using JET 4.0 since you're using access.

 

I'm probably offering bad advice at this point... can't really offer much of anything else on the topic. Maybe the MSDN can shed some light on to things and help you out;

 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbTypeClassTopic.asp

Gamer extraordinaire. Programmer wannabe.
Posted

Yeah, ODBC was working for a bit, it sent the time properly. But I guess I didn't pay attention when I was in the Data Adapter Wizard and it said it couldn't make an update function, because then it really wasn't working.

 

Another possible solution to this problem would be to use an ODBC connection, but somehow resolve this update problem.

Still getting my head around this ADO stuff... sigh.
Posted
A messagebox isn't good enoughl I need something that will store in an Access database.
Still getting my head around this ADO stuff... sigh.
  • *Experts*
Posted
Make sure your Access Db Date/Time field is formated as a "General Date" not as a "Long Date". The "General Date" formated column will allow dd/mm/yyyy hh:mm:ss am/pm type of datetime format. All other date/time fields are date or time only formated. You may then have to do a datepart or a string manipulation to appropriately format your datum for entry into the Access DB.
  • *Experts*
Posted
I noticed that DBDate won't transmit the time, so I want to switch it to a DBTimeStamp. But when I replace every occurence of DBDate with DBTimeStamp, It throws this:

 

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

 

I don't think I can change my Access database to handle this, I can only set a field as a Date/Time.

 

 

Clarification my previous post. In Design View, check the Data Type and assure it is Date/Time, then below, in the General tab, click Format. You should get a drop down arrow that will let you choose the format: Select General Date and try the code the way you were trying here.

 

 

Jon

  • *Experts*
Posted (edited)
I noticed that DBDate won't transmit the time, so I want to switch it to a DBTimeStamp. But when I replace every occurence of DBDate with DBTimeStamp, It throws this:

 

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

 

I don't think I can change my Access database to handle this, I can only set a field as a Date/Time.

 

Your AccessDB can handle a date/time in the format I showed you. Are you still trying to use TimeStamp? TimeStamp is supported in the SQL 99 standards. However, contrary to what you are expecting, it is like a combination of DATE and TIME and thus contains 4 digits for year and two each for month, date, hour, minute and second making a total of 14 digits in the form of a number. It would not be interpreted by your Accessdb as a date/time but as a number. It works as a unique number generator but I suspect it is not what you're looking for in your implementation.

 

 

Jon

Edited by jfackler
Posted

Well, I found the problem and fixed it. Instead of DBDate, I just used Date. Works perfectly.

 

I hate when problems have such easy solutions.

Still getting my head around this ADO stuff... sigh.
  • *Experts*
Posted

Funny... I *love* easy solutions :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
I love them too... but see, the thing is, I thought the problem was this really deep, widespread thing. It took me two days just to isolate it. And then I was so stubborn about getting a DBTimeStamp to work I didn't look at my other options.
Still getting my head around this ADO stuff... sigh.

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