我有一个带有名为约会的表的C#asp数据库。我将其中一个值的数据类型设置为Date,但是当我在表格上显示数据时,它会显示日期和时间。
无论如何我可以让它只显示日期吗?
StringBuilder table = new StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
con.Open();
SqlCommand cmd= new SqlCommand();
cmd.CommandText = "Select PatientName,AppointmentDate,AppointmentTime from [Appointment]";
cmd.Connection = con;
SqlDataReader rd = cmd.ExecuteReader();
table.Append("<table border='1'>");
table.Append("<tr><th>Pateint Name</th><th>Appointment Date</th><th>Appointment Time</th>");
table.Append("</tr>");
if(rd.HasRows)
{
if(rd.Read())
{
table.Append("<tr>");
table.Append("<td>"+rd[0]+"</td>");
table.Append("<td>"+rd[1]+"</td>");
table.Append("<td>" + rd[2] + "</td>");
table.Append("</tr>");
}
}
table.Append("</table");
PlaceHolder1.Controls.Add(new Literal{Text=table.ToString()});
rd.Close();
}
}
// removed two '}' chars, because they don't seem to be necessary.
我在ASP webform中的占位符中显示表。