This Way:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtDate" runat="server" />
</div>
</form>
C#:
protected void Page_Load(object sender, EventArgs e)
{
PopulateDate();
}
private void PopulateDate()
{
string conString = ConfigurationManager.ConnectionStrings["ConString2"].ConnectionString;
SqlCommand cmd = new SqlCommand("SELECT * FROM Date WHERE id = 1");
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con; sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
DateTime dt = Convert.ToDateTime((ds.Tables[0].Rows[0]["date"].ToString()));
string time= dt.ToShortTimeString();
string date = dt.ToShortDateString();
this.txtDate.Text = time + " " + date;
}
}
}
}
}
SQL:
CREATE TABLE [dbo].[Date](
[date] [datetime] NOT NULL,
[ID] [int] NULL
) ON [PRIMARY]