Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to Bind DateTime from col in database to Textbox

Posted on 2008-11-16
3
Medium Priority
?
546 Views
Last Modified: 2012-05-05
This should be easy, and probably is...but

How do I bind a short format of datetime from sql server 2005 database to a textbox? I tried using tostring().substring(0,10) but if there are nulls this causes error.

0
Comment
Question by:ChiBella
3 Comments
 
LVL 9

Expert Comment

by:amx
ID: 22975193
cast the column to a DateTime then use .ToShortDateTime()


((DateTime)column).ToShortDateTime()

Open in new window

0
 
LVL 1

Expert Comment

by:Votech
ID: 22990864
C#:
textBoxMessage.Text = column != DBNull.Value ? ((DateTime) column).ToShortDateString() : null;

VB.NET (should be close):
textBoxMessage.Text = IIf(column <> DBNull.Value ,  (CType(column, DateTime)).ToShortDateString() , Nothing);

Replace column with DB column var.
0
 

Accepted Solution

by:
ChiBella earned 0 total points
ID: 23251820
this is what worked for me:

txtOrdDate.Text = String.Format("{0:d}", orderDetail.ORDER_DATE);
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

575 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question