Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Sql Server And Date Datatype


Reply
 
Thread Tools Display Modes
  #1  
Old 09-11-2002, 09:40 AM
RajAntonyv RajAntonyv is offline
Regular
 
Join Date: Aug 2002
Posts: 53
Default Sql Server And Date Datatype


Hello,

I am having so much fun with this date datatype in SQL and VB.

I am trying to update a date column defined as smalldatetime and I am using a dtpicker to choose the date. I am using:

Set PerAcreRs = PerAcreConn.Execute("Update collection set collectionRddno = '" + txtColRddNo.Text + "', collectionamount = " + FormatCurrency(txtColAmount.Text, 2, vbTrue, vbFalse, vbFalse) + ", collectionstaffname = '" & _
txtStaffName.Text + "', collectiondate = " + Format(dtCol_CollectionDate.Value, "mm/dd/yyyy") + ", collectiontadmappg = '" + txtColTadMapPg.Text + "', collectionmapscopg = '" + txtMapscoPg.Text + "', collectioncheckdate =" & _
Format(dtColDateOnCheck.Value, "mm/dd/yyyy") + ", collectionreimbcheckno ='" + txtColReimbAdd_CheckNo.Text + "', collectioncomments ='" + txtColComments + "', CollectionDevTaxId_FK = '" + ColDevTaxId + "', CollectionLineNo_FK ='" & _
cmbColLineInfo.Text + "', CollectionLineSwrFrom_FK = '" + cmbColSwrStnFrom.Text + "', CollectionLineSwrTo = '" + cmbSwrStnTo.Text + "' where collectionrddno ='" + mshColSearch.Text + "'")

as my update statement. For some reason, all the dates come across as "1900-01-01 00:00:00".

I don't want to change the datatype because then I have to go and change lot of other code based on the date datatype.

I have been looking at this for hours trying different things but not been successful. I need another set of eyes for help.

Thanks and appreciate all your help,

Raj Antony V
Reply With Quote
  #2  
Old 09-11-2002, 09:58 AM
davie's Avatar
davie davie is offline
Senior Contributor
 
Join Date: Jun 2002
Location: Mayo, Eire
Posts: 967
Default

Try something like this for your date values.

Code:
"CONVERT(DATETIME,'" & Format(Me.dtpOrderFrom.Value - 1, "yyyy-mm-dd") & " 00:00:00',102) "
__________________
Davie
If at first you don't succeed; don't bother trying again, just go to the pub!
Why is a person that handles your money called a 'Broker'?
If quizzes are quizzical, what are tests? | Tiocfaidh ar La
Reply With Quote
  #3  
Old 07-31-2012, 09:55 AM
arunendra arunendra is offline
Newcomer
 
Join Date: Mar 2008
Posts: 1
Default Post date and time information into sql server using vb6

Hi

I know this is a very old post, but I still think some people will need this help. So here is the solution ....
First the problem : You need date and time info into the back end DB, i.e. sql server and you want to post this data through a vb6 form.
Solution : Use a parameterised statement to insert data.

Assumption : you have a table named StudentMaster where you need to put Student Registration number, student name, address, and the time of the entry.
Table columns : StudentRegNo, StudentName, StudentAddress, EntryTime
Statement :

dim str as string
str="insert into studentmaster (RegNo,StudentName,StudentAddress,EntryTime) Values(?,?,?,GETDATE())"
This last parameter is set as GETDATE(), and this function will help to insert the dateandtime value into sql server like 31/07/2012 9:12:00 PM

Hope this helps someone!

Arunendra
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->