我得到一個語法錯誤,我似乎沒有找到答案,我希望有人能夠看到我缺少的東西。語法錯誤ASP.NET
我想通過使用下面的代碼在數據庫中添加數據,但它會引發語法錯誤消息,我真的不明白爲什麼。
這是我的代碼:
// 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 protected]'.
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 protected]'.
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 protected]'.]
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
正如我已經說過,這是一個測試應用程序,它不會上線。感謝您的幫助和關注 – Geo 2012-03-08 05:47:36