Page 1 of 1

Visual Basic and SQL Server

Posted: Sat 14 Aug, 2010 12.14
by m-in-m
Before I detail my problem is detail, does anyone have much experience with Visual Basic (Studio 2010) and SQL Server?

I am building an application for work, using my limited experience of Visual Basic. This consists of a two day course on VBA (which brought the idea of the project to mind), the Internet and a book or two.

I have now reached the stage where I need a user to record a number of dates into a SQL Server database. In the application the user uses a DateTimePicker to select the date - presses a button and the database is updated. When they then search for that entry the date is sometimes returned incorrectly.

An example is: the user selects 12 August 2010. SQL records this as 2010-08-12 00:00:00 but the application when fed it back interprets it as 08 December 2010. I now realise that I need to either format my data being recorded into SQL, format the data returned by SQL, or both but am not sure how to do this.

Anyone able to help?

Re: Visual Basic and SQL Server

Posted: Sat 14 Aug, 2010 12.57
by Sput
I can't tell from the example if the database has the right end of the stick and is storing the date correctly. If it IS correct (you can tell by using some dates higher than 12) then you should be able to format what comes out of the database using the VB format() function. It's been a while since I used VB so it might not exist, but here's a page with some examples of using it for dates.

http://www.apostate.com/vb-format-syntax