Search code examples
c#.netado.netdatareader

Reading a date using DataReader


I read a string using this format with a data reader. How can I read in a date using similar format?

while (MyReader.Read())
{
    TextBox1.Text = (string)MyReader["Note"];
}

Solution

  • Try as given below:

    while (MyReader.Read())
    {
        TextBox1.Text = Convert.ToDateTime(MyReader["DateField"]).ToString("dd/MM/yyyy");
    }
    

    in ToString() method you can change data format as per your requirement.