0
 Date.Text = reader["dateintable"].ToShortDateString();

I want to get the date value from an sql table and display it in a textbox using executereader

1 Answer 1

1

You can use ToShortDateString if you have a DateTime. But you have just an Object. You need to cast it:

Date.Text = ((DateTime)reader["dateintable"]).ToShortDateString();

Another way is using GetDateTime, but you need the column-index first:

Date.Text = reader.GetDateTime(reader.GetOrdinal("dateintable")).ToShortDateString();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.