I'm loading data from my database into a DataTable, and one of the columns is a date field.
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "MySP";
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
dt.Load(rdr);
}
}
I'd like to format that column so that instead of containing a full date, it will be formatted like "MM/DD/YYYY".
I've tried looping through each row in the table and changing the cell for that column, but I get an error saying that the string isn't a valid DateTime object.
I tried changing the column DateType to a string, but I get an error saying I can't change the DateType after the table is filled.
How can I do this? This seems like such a simple thing, but I'm having so much trouble with it.
Load()