Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / August 2006

Tip: Looking for answers? Try searching our database.

Date/Time problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Devlon - 30 Aug 2006 02:03 GMT
Hi,

I've created a class With a few properties of type "date".
I also have a SQL-database (which I can't change) with columns of type
"datetime"

when I use ...

clsInfo.date = now()

... I can't pas the date to the database without errors...

When I create a date property of type string and I use it like this ...

clsInfo.dateString = "2006-12-2"

... it works fine...

Anyone any idea's ? Do I have to convert the date to string before sending
it to the database ?

thanx

John
GhostInAK - 30 Aug 2006 02:20 GMT
Hello John,

There's no need to convert it to string..

Dim tConnection As SqlConnection = New SqlConnection("connection string here")
Dim tCommand as SqlCommand = New SQlCommand

With tCommand
   .Connection = tConnection
   .CommandType = CommandType.Text
   .CommandText = "INSERT INTO someTable (dateField) VALUES (@dateValue)
   .Parameters.AddWithValue("@dateValue", Now)
End With

tConnection.Open
tCommand.ExecuteNonQuery
tConnection.Close

Enjoy,
-Boo

> Hi,
>
[quoted text clipped - 20 lines]
>
> John
Cor Ligthert [MVP] - 30 Aug 2006 06:27 GMT
In addition to Boo,

As you have done it correct of course and your DateTime is a real DateTime
field in your database and not a string as sometimes is done.

Cor

> Hello John,
>
[quoted text clipped - 42 lines]
>>
>> John

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.