473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to show a datetime field in a TextBox

ad
I have a datetime filed, name Birthday.
I use aTexBox.Text= ((DateTime)dr["Birthday"]).ToShortDateString();
but it result in an .InvalidCastException:

How can I datetime field in a TextBox?

Nov 17 '05 #1
5 3512
On Mon, 28 Mar 2005 21:56:53 +0800, "ad" <ad@wfes.tcc.edu.tw> wrote:
I have a datetime filed, name Birthday.
I use aTexBox.Text= ((DateTime)dr["Birthday"]).ToShortDateString();
but it result in an .InvalidCastException:

How can I datetime field in a TextBox?


What type is the Birthday column, and does it allow nulls?
--
Ludwig Stuyck
http://www.coders-lab.net
Nov 17 '05 #2
ad wrote:
I have a datetime filed, name Birthday.
I use aTexBox.Text= ((DateTime)dr["Birthday"]).ToShortDateString();
but it result in an .InvalidCastException:
That's because dr["Birthday"] doesn't evaluate to a DateTime instance
(or more precisely, a boxed DateTime struct).
How can I datetime field in a TextBox?


Like you are doing. Try printing dr["Birhtday"].GetType().FullName :)

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #3
hi,
what is dr ? it's a DataRow or a DataReader ?

what is the type of "BirthDay"column?

Does it support null ?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I have a datetime filed, name Birthday.
I use aTexBox.Text= ((DateTime)dr["Birthday"]).ToShortDateString();
but it result in an .InvalidCastException:

How can I datetime field in a TextBox?

Nov 17 '05 #4
ad

Thank
1. dr is a DataReader
2. the type of "BirthDay"column is DateTime
3. it support null

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> ¼¶¼g©ó
¶l¥ó·s»D:OC**************@TK2MSFTNGP14.phx.gbl...
hi,
what is dr ? it's a DataRow or a DataReader ?

what is the type of "BirthDay"column?

Does it support null ?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I have a datetime filed, name Birthday.
I use aTexBox.Text= ((DateTime)dr["Birthday"]).ToShortDateString();
but it result in an .InvalidCastException:

How can I datetime field in a TextBox?


Nov 17 '05 #5
Hi,

If it does support null you have to check for that:

textbox.Text = dr["Birthday"] == DBNull.Value? " N/A" :
((DateTime)dr["BirthDay"]).ToShortDateString();

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:ur**************@TK2MSFTNGP12.phx.gbl...

Thank
1. dr is a DataReader
2. the type of "BirthDay"column is DateTime
3. it support null

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
¼¶¼g©ó
¶l¥ó·s»D:OC**************@TK2MSFTNGP14.phx.gbl...
hi,
what is dr ? it's a DataRow or a DataReader ?

what is the type of "BirthDay"column?

Does it support null ?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
>I have a datetime filed, name Birthday.
> I use aTexBox.Text= ((DateTime)dr["Birthday"]).ToShortDateString();
> but it result in an .InvalidCastException:
>
> How can I datetime field in a TextBox?
>
>
>



Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Carl | last post by:
Hi, to be use with SQL server database 1- From window form textbox object From this assignement, txtTOTAL.Text="0.00m"; How do you convert back to decimal type ? How do you assign a...
8
by: Gidi | last post by:
hello, i have a textbox that represnts a date and i want to pare it to a DateTime, but sometimes this textBox can be empty string and i want to send it to the DataBase as null or as empty Date, how...
1
by: Lerp | last post by:
Hi all, What do I have to do in order to get my value from my textbox that is formatted like 'mm/dd/yyyy' into a datetime database field ? Currently getting an error: Syntax error converting...
3
by: Dabbler | last post by:
How do I display a datetime field that hasn't been assigned a value as blank instead of the default minimum value? I need to do this in both display and edit modes. Thanks!
1
by: hodgesp | last post by:
I have a Datagrid that I'm trying to use to update a SQL table. The grid works and I get the EditCommand to work. When I make a change to a field, I get a date error. I was getting invalid cast...
3
by: ad | last post by:
I have a web page which show a lot of data, it waste a lot of time to show the data. I wnat to know how much time it take to show the data. How can I get it?
5
by: Michel Posseth [MCP] | last post by:
Hello we have encountered the following problems with the date time picker control A : datetime picker control gives focus to last entered field when moving back and forward with focus how do...
1
by: Brad Pears | last post by:
I am using vb.net 2005 and SQL server 2000. In my table I have a date field of type "smalldatetime". In my vb application, the user may or may not enter a date value into the appropriate text box....
2
by: justin | last post by:
Hello all: I have a FormView that has it's DataSourceID set to a SqlDataSource that uses stored procedures for it's select, update, insert, and delete. I want the FormView to have an "autosave"...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.