Date & time field data updating
We will try to read a date and time field and populate the data in a text box. Then we can ask the users to edit the date and time value and update the record. Here we are asking users to change the data which has to be stored in a date and time field, so we have to check the entered data is a valid date and time or not. We will be using the IsDate to validate the date and time data entered by user. One if condition checking we will do and it is passed ( true ) then only the query to update the record will be executed, else the corresponding error message will be displayed.
Here we are using one table name dt which has three columns ( fields ), book_id one auto MSSQL increment identity column , issue_dt one date and time field & return_dt one date and time field ( note that date and time fields here are not short date and time field.) . We will try to collect a record with book_id = 5 and update the same record. You can download the table structure with data at the end of this page.
Table structure is here
conn.ConnectionString = aConnectionString
Set rs =Server.CreateObject("ADODB.Recordset")
if isDate(dtt) Then
rs.open " update dt set issue_dt='" & dtt & "' where book_id=5 " , conn
Response.Write " Wrong Date format "
'Displaying data from the table.
rs.open " select book_id, issue_dt from dt where book_id=5 " , conn
if rs.EOF Then
Response.Write "No Record exist"
Response.Write "<form method=post action='' ><input type=hidden name=todo value=update><input type=text name =dtt value= '" & rs("issue_dt") & "'><input type=submit value=Update></form>"
Response.Write "After the update <br>Book Id: " & rs("book_id") &" Issude Date: " & rs("issue_dt")
Set rs = Nothing
Set conn = Nothing
CREATE TABLE [dbo].[dt] (
Table data is here
[book_id] [int] IDENTITY (1, 1) NOT NULL ,
[issue_dt] [datetime] NOT NULL ,
[return_dt] [datetime] NOT NULL
) ON [PRIMARY]
3,2007-08-23 00:00:00,2007-09-25 00:00:00
4,2007-12-15 00:00:00,2008-01-02 00:00:00
5,2007-07-05 19:59:56,2007-07-20 19:54:56
This article is written by plus2net.com team.
Be the first to post comment on this article :