DateTime Format using DataTable

Hello Experts,

I need to retrieve data from my DB to a TextBox Control and when I return it the datetimie data it is returned in this format 10/2/2011 12:00:00. I would like it to just display 10/2/2011 if possible.

The following label beow is what I need formatting help with.

txtDate.Text = data["csch_startdate"].ToString();



    protected void RetrieveCourseScheduleToUpdateValues()
    {
        int csch_id = Convert.ToInt32(Request.QueryString["csch_id"]);

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HealthCourses"].ConnectionString))
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "HealthCourses_RetrieveCourseScheduleByIDForUpdate";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = conn;

            cmd.Parameters.AddWithValue("@csch_id", SqlDbType.Int).Value = csch_id;

            DataTable dtCourseToUpdate = new DataTable();
            SqlDataAdapter adp = new SqlDataAdapter();

            try
            {
                conn.Open();

                adp.SelectCommand = cmd;
                adp.Fill(dtCourseToUpdate);

                if (dtCourseToUpdate != null)
                {
                    DataRow data = dtCourseToUpdate.Rows[0];
                    hfv_csch_id.Value = data["csch_id"].ToString();
                    lblCourseNameResult.Text = data["ghaco_name"].ToString();
                    ddlInstructor.SelectedValue = data["hmi_id"].ToString();
                    txtDate.Text = data["csch_startdate"].ToString();
                    txtStartTime.Text = data["csch_starttime"].ToString();
                    txtEndTime.Text = data["csch_endtime"].ToString();
                }
            }

            catch (Exception ex)
            {
                ex.Message.ToString();
            }

            finally
            {
                conn.Close();
            }
        }
    }
LVL 4
asp_net2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jagssiduralaCommented:
write code  as below

txtDate.Text = String.Format("{0:MM/dd/yyyy}", data["csch_startdate"]);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jagssiduralaCommented:
0
brutaldevCommented:
Parse the string to a DateTime object first, then ToString it with your desired format.
DateTime.Parse(data["csch_startdate"].ToString()).ToString("dd/MM/yyyy");

Open in new window

0
brutaldevCommented:
jagssidurala beat me to it, using String.Format in his example is neater as well.
0
asp_net2Author Commented:
Thank you both!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.