把数据库中的datatime类型字段 用字符串的形式输出(如05-20-2012)

来源:互联网 发布:酒店智能门锁 网络 编辑:程序博客网 时间:2024/06/05 08:14
SqlConnection con = new SqlConnection("server=localhost;database=bookmanage;uid=sa;pwd=1234");        con.Open();        string sql = "SELECT ID,CONVERT(VARCHAR(10),nowdate ,110) as 时间 FROM InsertTime where ID=4";        DataSet ds = new DataSet();        SqlDataAdapter da = new SqlDataAdapter(sql,con);        da.Fill(ds, "table");        TextBox2.Text = ds.Tables[0].Rows[0]["时间"].ToString();


其中  nowdate  为 数据库中字段 其类型为 datatime

 

SELECT ID,CONVERT(VARCHAR(10),nowdate ,110) as 时间 FROM InsertTime