Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:42:39+00:00 2026-06-14T03:42:39+00:00

I have a date in a DataTable (dt). How to read a Date from

  • 0

I have a date in a DataTable (dt). How to read a Date from a DataTable into a textbox

I can read a string in fine:

    tbEvent.Text = dt.Rows[0].Field<String>(0); 

I tried this but I get an error:

Unable to cast object of type ‘System.DateTime’ to type
‘System.String’.

        tbDate.Text = dt.Rows[0].Field<DateTime>(1);

Regards
Tea

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:42:41+00:00Added an answer on June 14, 2026 at 3:42 am

    try

     tbDate.Text = dt.Rows[0].Field<DateTime>(1).ToString();
    

    Textbox.Text only accepts string values – so you need to convert.

    Updated

    To format the string to show specific values you can use the custom format strings – http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

    so the above becomes

     tbDate.Text = dt.Rows[0].Field<DateTime>(1).ToString("dd/MM/yyyy");
    

    for db date 12/23/2012 12:25:45 it will produce 23/12/2012.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataTable according to the Client Requirement it can contain invalid date
I have the datatable below : qty price date 5 2 1/25 6 1
I have a untyped DataTable that looks like this (srcTbl): date col_1 col_2 ...
I have a date in String format, mm/dd/yyyy I want to convert this to
I have a date in XML: <time>1340517600</time> How can I convert it to a
I have a DataTable which has 10 columns, and after I add some rows
I have a DataTable whose data is being fed into a Class: MyProperty =
I have a DataTable with a DateTime column, DateCol, that can be DBNull. The
I Have a Datagridview bound to a datatable wich hold data from a database
i have a datatable i created below i need to list all rows' cell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.