下午。
我需要帮助尝试将我的 Windows 登录名 名称和当前日期 从我的 中的表单 添加到我的当前数据库中cshtml 文件。请记住,我对此很陌生……我才刚刚开始理解 HTML。
我使用的工具: WebMatrix 3, 火狐
数据库名称为: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>
最佳答案
我设法解决了我自己的问题,感谢我的一个 friend (为英国人欢呼)的提示。
现在 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 表单将系统日期、时间和 Windows 登录信息保存到我的 .sdf 数据库中
关于database - 通过 cshtml 表单将 Windows 登录名和当前日期添加到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25896132/