Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 12th, 2005, 01:18 PM
Authorized User
 
Join Date: Nov 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default show date in textbox

in my database, i have a column which is of type "datetime". but i can't display it in my textbox. why?

when i look in query analyzer, the date format is "yyyymmdd hh:mm:ss". i want to have year, month and day only, is there any way for me to do that?

yengzhai
__________________
yengzhai
 
Old February 12th, 2005, 03:00 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

when you fetch it from DB through a DataSet or DataReader you can simply cast it and then work on DateTime value...
Code:
DateTime dt=objDataReader.GetDateTime(ColumnNumber);
//or DataSet
DateTime dt=(DateTime)ds.Tables[0].Rows[0](ColumnNumber);
textbox.Text=dt.ToString(FormatString for DateTime)
look up MSDN for DateTime and FormatString..

_____________
Mehdi.
software student.
 
Old February 12th, 2005, 06:15 PM
Authorized User
 
Join Date: Nov 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot, mehdi!!! it works!!!

but here i have one more problem, now the problem is i can't update date into my database. it works only when i change the datatype "datetime" to "varchar". what i want to do is to fetch data (date) from database into textbox, then modify it and update it back to database. but i can't do so due to the problem that i mention above. help me pls... :(

yengzhai
 
Old February 13th, 2005, 02:53 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

when you want to update a datetime column in DB you should use DateTime structure,there is a table mapping,
nvarchar(sql)---------->System.string(.NET)
datetime(sql)---------->System.DateTime(.NET)
Money(sql)---------->System.Decimal(.NET)
so you should convert your string in the TextBox to DateTime by Parse method,something like below
Code:
//check for syntax..
DateTime dt=DateTime.Parse(TextBox1.Text);
SqlConnection objConnection=new SqlConnection(strConnection);
string upd="Update Employees SET BirthDate=@BirthDate";
upd+=" WHERE EmployeeID=@EmployeeID";
SqlCommand updCommand=new SqlCommand(upd,objConnection);
updCommand.Parameters.Add("@BirthDate",SqlDbType.DateTime);
updCommand.Parameters["@BirthDate"].Value=dt;
updCommand.Parameters.Add("@EmployeeID",SqlDbType.Int);
updCommand.Parameters["@EmployeeID"].Value=1;
objConnection.Open();
updCommand.ExecuteNonQuery();
objConnection.Close();
_____________
Mehdi.
software student.
 
Old February 15th, 2005, 11:45 AM
Authorized User
 
Join Date: Nov 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks again, mehdi, you are really helpful! thanks!

yengzhai





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show date format in GridView khb3283 ASP.NET 2.0 Basics 1 October 4th, 2008 11:45 AM
Show Images from Start Date thru Date istcomnet Classic ASP Basics 2 May 23rd, 2008 07:12 AM
show date/time in a datagrid. mehmetned C# 2005 0 March 23rd, 2007 08:43 AM
show date/time in a datagrid. mehmetned ASP.NET 1.0 and 1.1 Basics 0 March 23rd, 2007 08:38 AM
show dynamic textbox when radiobuttonlist selected debjanib ASP.NET 1.0 and 1.1 Professional 1 May 30th, 2006 09:42 PM





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