Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
  #2 (permalink)  
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
  #3 (permalink)  
Old February 20th, 2006, 04:24 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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.
  #4 (permalink)  
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
  #5 (permalink)  
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.