string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataDirectoryMengXianHui.mdb;Persist Security Info=True";
string QueryString = "Insert Into [Document] (Title, Content, Author, CreateDate) Values(@Title, @Content, @Author, @CreateDate)";
OleDbConnection cn = new OleDbConnection(ConnectionString);
cn.Open();
OleDbCommand cmd = new OleDbCommand(QueryString, cn);
cmd.Parameters.AddWithValue("@Title", Title);
cmd.Parameters.AddWithValue("@Content", Content);
cmd.Parameters.AddWithValue("@Author", Author);
cmd.Parameters.AddWithValue("@CreateDate", DateTime.Now);
cmd.ExecuteNonQuery();
cn.Close();
cn.Dispose();
解决办法就是将上面语句中的 cmd.Parameters.AddWithValue("@CreateDate", DateTime.Now); 转换成下面的语句即可:
OleDbParameter parameter = new OleDbParameter();
parameter.OleDbType = OleDbType.DBDate;
parameter.Value = DateTime.Now;
cmd.Parameters.Add(parameter);