2
    using (SqlConnection conn = conMgr.GetDatabaseConnection())
    {
        using (SqlCommand cmd = new SqlCommand("getEdit", conn))
        {


            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@id", id));
            cmd.Connection = conn;
            using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) 
            { 
                  while (rdr.Read()) 
                     {
                        TextBox1.Text = rdr.GetInt32(rdr.GetOrdinal("id")).ToString(); 
                        TextBox2.Text = rdr.GetString(rdr.GetOrdinal("name"));
                        DropDownList4.SelectedValue = rdr.GetString(rdr.GetOrdinal("country"));
                        string dt = rdr.GetString(rdr.GetOrdinal("dob"));
                        Label14.Text = dt;




                     }  
                rdr.Close();
            }
        }

dob 是日期时间类型。所以请告诉我如何使用标签显示它。如何将日期时间对象转换为 srting 类型。

4

1 回答 1

5

您需要使用GetDateTime,然后您可以使用ToShortDateStringdd/mm/yyyy 格式获取它:

string dt = rdr.GetDateTime(rdr.GetOrdinal("dob")).ToShortDateString();
Label14.Text = dt;
于 2013-10-03T08:09:39.407 回答