.net急急急!

来源:百度知道 编辑:UC知道 时间:2024/05/30 00:20:16
string db = Server.MapPath("~/App_Data/qzzp.mdb");
string strConnectionStr = "Data Source=" + db + ";Provider=Microsoft.Jet.OLEDB.4.0";
//定义并实例化数据库连接对象并打开
OleDbConnection myconn = new OleDbConnection(strConnectionStr);
myconn.Open();

string s_title = txtBiaoti.Text;
string s_content=txtNeirong.Text;
string sql = "insert into contents(title,content,time)values('" + s_title + "','" + s_content + "','" + DateTime.Now.ToString() + "')";
OleDbCommand cmd = new OleDbCommand(sql, myconn);
cmd.ExecuteNonQuery();
Response.Redirect("../index.aspx");
myconn.Close();

DateTime.Now.ToString()这句话不对,怎么写可以显示时间啊?

查查你有没其他错误吧,我用DateTime.Now.ToString()是可以的啊!!
也可以成功往数据库添加的

DateTime.Now.ToShortDateString();
类似还有很多,比如
DateTime.Now.ToShortDateString();
DateTime.Now.ToShortTimeString();
等等

DateTime.Now.ToLongTimeString()

你数据库里time的类型是什么?如果是DateTime类型的话,直接DateTime.Now,不需要ToString()

不用ToString()New本身就是String类型的