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是日期时间类型。所以请告诉我如何使用标签显示它。如何将日期时间对象转换为字符串类型。
答案 0 :(得分:5)
您需要使用GetDateTime
,然后您可以使用ToShortDateString
以dd / mm / yyyy的格式获取它:
string dt = rdr.GetDateTime(rdr.GetOrdinal("dob")).ToShortDateString();
Label14.Text = dt;