構文エラーが発生しましたが、回答が見つからないようで、誰かが私が見逃しているものが見えるようになることを期待していました。構文エラー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