将系统日期、时间和windows登录保存到我的.sdf数据库中
下午。
我需要帮助从cshtml文件中的表单将我的Windows登录名和当前日期添加到我的当前数据库中。请记住,我对此很陌生。。。我才刚刚开始理解HTML。
我使用的工具:WebMatrix 3,Firefox
数据库名称为:sweep hazmat library.sdf
表名为:kl1explosiv
以下是代码:
{
var db = Database.Open("sweep hazmat library");
var ASIN = "";
var description = "";
var dateadded = "";
var addedby = "";
if(IsPost){
//read ASIN.
ASIN = Request["ASIN"];
if (ASIN.IsEmpty()){
Validation.Equals("ASIN", "A Article is needed here");
}
//read description.
description = Request["description"];
if (description.IsEmpty()){
Validation.Equals("description", "a description is required");
}
//figure out how to add date automatically.
dateadded = Request["DateTime.Now"];
addedby = ;
var SQLINSERT =
"INSERT INTO kl1explosiv (ASIN, description, dateadded){Values (@0, @1, @datetime.now )";
db.Execute(SQLINSERT, ASIN, description, dateadded, addedby);
Response.Redirect("~/EntsorgungsTabelle.cshtml");
}
<html>
<head>
</head>
<body>
<h2>Add an Article</h2>
<form method="post">
<fieldset>
<p><label for="ASIN">Title:</label>
<input type="text" name="ASIN" value="@Request.Form["ASIN"]" />
@Html.ValidationMessage("ASIN")
</p>
<p><label for="description">beschreibung:</label>
<input type="text" name="description" value="@description" />
@Html.ValidationMessage("description")
</p>
<p><input type="datetime-local" name="Dateadded" value="@dateadded" />
</p>
<p><input type="submit" name="buttonSubmit" value="Add an Article" /></p>
</fieldset>
</form>
</body>
</html>
我设法解决了自己的问题,感谢我的一个朋友(为英国人欢呼)的提示。
现在,Windows登录也将自己与当前日期一起添加到数据库中:
@{
var db = Database.Open("sweep hazmat library");
var asin = "";
var description = "";
var dateadded = DateTime.Now;
var addedby = Environment.UserName;
var now = DateTime.Now;
if(IsPost){
//read ASIN.
asin = Request["asin"];
if (asin.IsEmpty()){
Validation.Equals("asin", "A Article is needed here");
}
//read description.
description = Request["description"];
if (description.IsEmpty()){
Validation.Equals("description", "a short description is needed here");
}
//figure out how to add date automatically.
dateadded = DateTime.Now;
addedby = Environment.UserName;
var SQLINSERT = "INSERT INTO kl1explosiv (asin, description, dateadded, addedby) Values(@0, @1, @2, @3)";
db.Execute(SQLINSERT, asin, description, dateadded, addedby);
db.Close();
Response.Redirect("EntsorgungsTabelle.cshtml");
}
}
<html>
<head>
</head>
<body>
<time datetime="@now.ToString("o")" pubdate>@now.ToLongDateString() @now.ToShortTimeString()</time>
@addedby
<h2>Add a Movie</h2>
@Html.ValidationSummary()
<form method="post">
<fieldset>
<legend>Movie Information</legend>
<p><label for="ASIN">Title:</label>
<input type="text" name="ASIN" value="@Request.Form["ASIN"]" />
@Html.ValidationMessage("ASIN")
</p>
<p><label for="description">beschreibung:</label>
<input type="text" name="description" value="@description" style="width: 250px; height: 50px;"/>
@Html.ValidationMessage("description")
</p>
<p><input type="submit" name="buttonSubmit" value="Add an Article" /></p>
</fieldset>
</form>
</body>
</html>
现在,我可以通过.cshtml表单