[英]Using ASP.NET to Insert Data into a Database
I have a form on my web page that I want posting to my database in the background upon submitting the form. 我的网页上有一个表单,想要在提交表单时在后台将其发布到数据库中。 Here is my code: 这是我的代码:
if (Validation.IsValid())
{
// Insert a new user into the database
var db = Database.Open("StarterSite");
// Check if user already exists
var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", email);
if (user == null) {
// Insert email into the profile table
db.Execute("INSERT INTO UserProfile (Email) VALUES (@0)", email);
}
}
This is sample code and I'm trying to interpret it. 这是示例代码,我正在尝试解释它。 What's baffling me is that is says VALUES (@0)
. 让我感到困惑的是说VALUES (@0)
。 However, when the form on this page is submitted, it still manages to post the inputted email address though the value says ( @0
) ? 但是,提交此页面上的表单后,尽管值显示为( @0
)?,它仍然设法发布输入的电子邮件地址。
Any clarity would be greatly appreciated! 任何清晰度将不胜感激!
Regards, 问候,
Josh 乔希
(PS, I'm new to ASP.NET) (PS,我是ASP.NET的新手)
@0 refers to the first parameter. @ 0表示第一个参数。 In your case it is the variable email
as so; 您的情况就是可变email
;
db.Execute("INSERT INTO UserProfile (Email) VALUES (@0)", email);
You can insert more than one ordered parameter like this; 您可以像这样插入多个有序参数;
db.Execute("INSERT INTO UserProfile (Email, SecondParam) VALUES (@0, @1)", @0, @1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.