gpt4 book ai didi

c# - 语法错误 ASP.NET

转载 作者:太空宇宙 更新时间:2023-11-03 19:24:45 24 4
gpt4 key购买 nike

<分区>

我遇到了一个语法错误,我似乎找不到答案,我希望有人能够看到我遗漏了什么。

我正在尝试使用以下代码在数据库中添加数据,但它会抛出一条语法错误消息,我真的不明白为什么。

这是我的代码:

 // Get data from textboxes.
string last = txtLastName.Text;
string first = txtFirstName.Text;
string gender = txtGender.Text;
string email = txtEmail.Text;
int age = int.Parse(txtAge.Text);
string pref = "";
// Compose SQL command string.
string sql = "INSERT INTO Applicant VALUES" +
"('" + first + "', '" + last +
"', '" + gender + "', '" + age + "', " + email + ");";

这是错误信息

Syntax error (missing operator) in query expression 'email.example@email.com'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'email.example@email.com'.

Source Error:


Line 50: // Create command object and execute insert statement.
Line 51: OleDbCommand command = new OleDbCommand(sql, c);
Line 52: command.ExecuteNonQuery();
Line 53:
Line 54: // Close connection.

Source File: d:\DePaul\Winter 2012\IT 330\Projects\Proj5-Nicolaides\Proj5-Nicolaides\application-form.aspx Line: 52

Stack Trace:


[OleDbException (0x80040e14): Syntax error (missing operator) in query expression 'email.example@email.com'.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +992124
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
ASP.application_form_aspx.btnSubmit_Click(Object sender, EventArgs e) in d:\DePaul\Winter 2012\IT 330\Projects\Proj5-Nicolaides\Proj5-Nicolaides\application-form.aspx:52
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Version Information: Microsoft .NET Framework Version:2.0.50727.5448; ASP.NET Version:2.0.50727.5456

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com