473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

System.DateTime doesn't convert to SqlDbType.DateTime

If I use this simple code

SqlParameter param = new SqlParameter( "@param", SqlDbType.DateTime );
param.Value = System.DateTime.Now;

param.Value is "11/2/2005" rather than "11/2/2005 10:42:15 AM"

How do I get it so the sql value is the same as the C# value, and not
truncated?

Nov 17 '05 #1
3 13026
Narshe,

Are you basing this on what you see in the debugger for Value? Have you
looked at the object itself and found that the time values are actually
zero? When you persist it ack to the database, does it not include the
time?

If this is the case, then have you tried using the constructor to
SqlDateTime which takes a DateTime parameter, and setting it like that?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Narshe" <na****@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
If I use this simple code

SqlParameter param = new SqlParameter( "@param", SqlDbType.DateTime );
param.Value = System.DateTime.Now;

param.Value is "11/2/2005" rather than "11/2/2005 10:42:15 AM"

How do I get it so the sql value is the same as the C# value, and not
truncated?

Nov 17 '05 #2
I have not tried that constructor yet. I noticed that doing a
ToString() on the value gives the correct value, but the short value is
persisited across to the db also.

I'll give that other constructor a try also.

Nov 17 '05 #3
I got it working, thanks for the help.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
3
by: Vicki Carlsen | last post by:
Hi, What is the easiest way to convert a DateTime object to a long?? - And the other way back?? (For database use) Regards, Vicki
2
by: Thomas Lindroos | last post by:
how to convert this??? string strDate = "19701105"; DateTime myDate = System.Convert.ToDateTime(strDate); ideas anyone /thomas lindroos
2
by: jason | last post by:
hello all, silly question, but i can't find a thread that answers it. i have stored procedures that have output parameters of the datatypes Money and DateTime. i have the following sample...
2
by: ad | last post by:
I use a textbox for user to enter a date. How can I determine if the string can convert to datetime.
0
by: Harry Haller | last post by:
The context is shown below in the getGames() method. I get errors on these lines: dtGames.Rows = (TimeSpan)dtGames.Rows; dtGames.Rows = (DayOfWeek)dtGames.Rows; because the playDate column...
5
by: Fabio | last post by:
Hi all! A simple question: I need to convert a DateTime var to a byte (or to a Int64). How? Thanks! --
1
by: A.Neves | last post by:
Hi, I'm having a problem, I have a DateTime value in Portuguese representation (dd-mm-yyyy) and I'm using SQLServer2005 with its default language English (yyyy-mm-dd), so when I assemble a WHERE...
0
by: Steve Kershaw | last post by:
Hi, I have a table in a SQL Server 2005 database that has a column of type "datetime". From a C# program I need to insert todays date into this column like so: gridAdapter.InsertNewGridID(...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.