I am trying to read a date field from database and set it to a label field. Im using the following code,
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select BirthDate from Student where Name=@name", con);
cmd.Parameters.AddWithValue("@name", "Mano");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
lblName.Text = dt.Rows[0]["Date"].ToString();
But this displays the data value in label in the format 02-05-1991 00:00:00 but I want to display it in format dd-mm-yyyy as 05-02-1991. So I tried the following code:
lblName.Text = dt.Rows[0]["BirthDate"].ToString("dd-mm-yyyy");
But it shows this error:
No overload for method ToString takes 1 argument
How can I change the format?