Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Re: aspx digest: May 20, 2002


Message #1 by Shreekar Joshi <joshishreekar@y...> on Mon, 20 May 2002 23:58:37 -0700 (PDT)
Hi,

Try this:
>     strSQL = "Insert into CustomerOrder(UserNumber,
> TotalAmount, 
> DateAdded) values (" + CStr(Session("UserID")) _
> 		   + ", " + CStr(Session("TotalAmount")) + ", '" +
> strToday 
> + "')"
-- Note the single quotes added in the string before
after strToday. This is OK if the datatype of the
field is String/Character/Text in the table design.
-- However, if the datatype is datetime in the table
design, use "#" instead of the single quote.

Regards
Shreekar Joshi


> Subject: entering correct date
> From: soni29@h...
> Date: Mon, 20 May 2002 21:50:45
> X-Message-Number: 1
> 
> hi,
> i had a slight problem with date, i'm making a page
> where the user is able 
> to purchase goods, once completed and accepted the
> date of purchase should 
> be entered into the database in a table.  i used the
> code that was given 
> in the beg. asp.net book but i keep getting the date
> around the year 1899, 
> not sure why? here is the code for that page:
> 
> <%@ Page Language="VB" aspcompat=true Debug=true%>
> <%@ Import Namespace="System.Data" %>
> <%@ Import Namespace="System.Data.Oledb" %>
> 
> <Script language="VB" Runat="Server">
> Sub Page_Load()
>   Dim objCC As Object
>   Dim strCardNumber As String
>   Dim blnIsValid, blnApproved As Boolean
>   Dim strConnection, strSQL as String
>   Dim objConnection as Object
>   Dim objCommand as oledbCommand
>   Dim dtoday, temptoday as Date						' 
> Two Date variables
>   Dim strToday as String						
> 	' A string to hold today's date
>  
>   If Len(Request("CardNumber")) > 0 Then			' Is the 
> number blank?
>     strCardNumber = Request("CardNumber")
>     blnIsValid = True
>   Else 
>     blnIsValid = False
>   End If
> 
>   if blnIsValid Then						
>     objCC 
> Server.CreateObject("CCObject.ProcessCard")		'
> Create 
> an instance of the object
>     blnApproved 
> objCC.IsValidCreditCardNumber(strCardNumber)	' Get 
> approval
>   End If
> 
>   If blnApproved Then
>     dtoday = Now()				' Get the date and time
>     temptoday = GetOnlyDate(dtoday)		' Get only the
> date, chop 
> off time portion
>     strToday = CStr(temptoday)		' Cast Date to
> String  
>     strConnection 
> "Provider=Microsoft.Jet.OLEDB.4.0; Data 
> Source=C:\BegASPNET\Assign5\CIS433.mdb"
>     strSQL = "Insert into CustomerOrder(UserNumber,
> TotalAmount, 
> DateAdded) values (" + CStr(Session("UserID")) _
> 		   + ", " + CStr(Session("TotalAmount")) + ", " +
> strToday 
> + ")"
>    
>     Result.Text = "Your card was approved, Thank
> you." 			
> 		' Card was approved
>     
>     objConnection = New
> OledbConnection(strConnection)			
> 		' Create the connection
>     objCommand = New OledbCommand(strSQL,
> objConnection)		
> 		' Create the command
>     objConnection.Open()						
> 						' Open the connection
>     objCommand.ExecuteNonQuery()					
> 					' Insert data into table
>     
>     objConnection.close()						
> 						' Close the connection
>   Else
>     Result.Text = "<b><font color = red>Sorry, but
> your card was 
> declined</font></b>"					' Card was declined
>   End If
> End Sub
> 
> ' Function used to chop of time and return only the
> date portion of a Date 
> object
> Function GetOnlyDate(dtoday as Date) As Date
> 	Return DateValue(DateAdd("d", 0, dtoday))
> End Function
> </Script>
> 
> <HTML>
> <HEAD></HEAD>
> <BODY>
> 
> <asp:Label id="Result" Runat="Server" />
> 
> </BODY>
> </HTML>
> 
> Thank you.
> 
> 
> ---
> 
> END OF DIGEST
> 


__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

  Return to Index