Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2006, 07:36 AM
Authorized User
 
Join Date: Feb 2006
Location: ahmedabad, Gujarat, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to insert date in Sql Server through aspx page

i m not getting insertion by Cdate(txt1.text) method

How to insert date in Sql Server through aspx page ??

pls send me sample code .

thnk
 
Old February 20th, 2006, 01:04 AM
Registered User
 
Join Date: Feb 2006
Location: Banglore, Karnataka, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default


  In aspx default date format is dd/mm/yyyy. But in MSSQL it is mm/dd/yyyy. So it is best to use varchar/char data type in MSSQL.

saas
 
Old February 20th, 2006, 04:24 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No offense, but this is probably the worst advice I have seen in a long time.

First of all, the statement about defaults in ASP and SQL is incorrect. The truth is: this depends largely on your regional settings. You may see different behavior on, say, a Dutch and an English OS.

By storing dates as varchars, you loose all structural meaning of a date. Is 10/04/2004 a date entered by an American programmer representing October 4, or has it been entered by a Dutch programmer representing April 10? You can't tell anymore.

The trick is to store a date in a universal format that the database understands. The format is the ISO date. If you store date like this:

2006/02/04

the database understands it's Feb 4, and nothing else.

If you store dates in a universal format in the database, it will always represent a useful date. This means you can use functions like Day, Month etc to get the required parts from that date.

So, in short: don't store dates as text; you'll regret that pretty soon. Just store them in a universally understood format.

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 20th, 2006, 07:54 AM
Authorized User
 
Join Date: Feb 2006
Location: Singupuram, Srikakulam, Andhra Pradesh, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai friend,

    Here I am sending a function, which converts dd/mm/yyyy to mm/dd/yyyy or vice versa.

   Then you can insert date to sqlserver easily.

The code is as follows.
----------------------
static public string DateConverterIntoDMY(string date)
{
if(date.CompareTo ("")!=0)
  {
        string delimiterStr ="/";
    char [] delimiter;
    string [] split = null;
    delimiter = delimiterStr.ToCharArray();
    split = date.Split (delimiter,3);
    string temp;
    temp = split[0];
    split[0]=split[1];
    split[1]=temp;
    string DMYformat = "";
    for(int i =0;i<3;i++)
    {
    DMYformat+= split[i];
    if(i<2) DMYformat+="/";
    }
    return DMYformat;
  }
else return "";
}

Thanks and Regards

Gowtham Sen
 
Old February 20th, 2006, 08:53 AM
Authorized User
 
Join Date: Feb 2006
Location: Singupuram, Srikakulam, Andhra Pradesh, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai friend,

    Here I am sending a function, which converts dd/mm/yyyy to mm/dd/yyyy or vice versa.

   Then you can insert date to sqlserver easily.

The code is as follows.
----------------------
static public string DateConverterIntoDMY(string date)
{
if(date.CompareTo ("")!=0)
  {
        string delimiterStr ="/";
    char [] delimiter;
    string [] split = null;
    delimiter = delimiterStr.ToCharArray();
    split = MyString.Split (delimiter,3);
    string temp;
    temp = split[0];
    split[0]=split[1];
    split[1]=temp;
    string DMYformat = "";
    for(int i =0;i<3;i++)
    {
    DMYformat+= split[i];
    if(i<2) DMYformat+="/";
    }
    return DMYformat;
  }
else return "";
}

Thanks and Regards


Gowtham Sen




Similar Threads
Thread Thread Starter Forum Replies Last Post
Sql Insert -- date format issue feets Access VBA 2 June 12th, 2007 12:11 PM
INSERT DATE INTO SQL SERVER prasanta2expert ASP.NET 1.0 and 1.1 Basics 1 January 4th, 2007 08:27 AM
Urgent: word file on aspx page from sql server bijgupt ASP.NET 1.0 and 1.1 Professional 5 November 15th, 2006 07:27 AM
Tring to insert date into SQL server Db srjordan Classic ASP Databases 1 August 15th, 2005 06:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.