日期:2010-01-05 浏览次数:20408 次
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- string connStr = "Server=.;Database=Test;uid=sa";
- SqlConnection conn = new SqlConnection(connStr);
- SqlCommand comm = new SqlCommand("select NowDt from Table1 where DtId = 1", conn);
- System.DateTime aa;//数据库中存的时间
- System.DateTime bb;//当前时间
- //取数据库中时间,字段是varChar类型
- try
- {
- conn.Open();
- aa = Convert.ToDateTime(comm.ExecuteScalar().ToString());//数据库时间,object转为string转换为DateTime
- conn.Close();
- }
- catch(Exception exp)
- {