[英]Can anyone help me resolve this db query error?
On execution, I get this error message:执行时,我收到此错误消息:
There was an error parsing the query. [ Token line number = 1,Token line offset = 116,
Token in error = No ]
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.SqlServerCe.SqlCeException: There was an error parsing the query. [ Token line number = 1,Token line offset = 116,Token in error = No ]
Source Error:源错误:
Line 40: "Nationality, Passport No, Occupation, PaymentMethod) " +
Line 41: "VALUES ( @0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10 )";
Line 42: db.Execute(bookingSql,
Line 43: surname,
Line 44: name,
Here's My code below: Ps I am new to programming help me out!!这是我的代码如下: Ps 我是编程新手帮助我!!
@{
Layout = "~/Shared/_Layout.cshtml";
Page.Title = "Make your reservations";
var surname="";
var name="";
var email="";
var arrivalDate = DateTime.MinValue;
var departureDate=DateTime.MinValue;
var city = "";
var country = "";
var nationality = "";
var passportno = "";
var occupation="";
var paymentmethod="";
if (IsPost)
{
surname = Request["surname"];
name = Request["name"];
email = Request["email"];
arrivalDate = Request["arrivalDate"].AsDateTime();
departureDate = Request["departureDate"].AsDateTime();
city = Request["city"];
country = Request["country"];
nationality = Request["nationality"];
passportno = Request["passportno"];
occupation = Request["occupation"];
paymentmethod = Request["paymentmethod"];
// Validate Reservation Details
if (name.IsEmpty()) {
ModelState.AddError("name", "Your name is required.");
}
if (surname.IsEmpty()) {
ModelState.AddError("surname", "Your Surname is required.");
}
// Save Reservation
var db = Database.Open("ElimGuestHouseData");
var bookingSql = "INSERT INTO Booking (Surname, Name, EmailAddress," +
"ArrivalDate, DepartureDate, City, Country, " +
"Nationality, Passport No, Occupation, PaymentMethod) " +
"VALUES ( @0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10 )";
db.Execute(bookingSql, surname, name, email, arrivalDate,
departureDate, city, country, nationality, passportno,
occupation, paymentmethod);
Response.Redirect("Reservationcomplete");
}
}
<h1>Reservation</h1>
<form action="Reservation" method="post">
<p>
@Html.Label("Surname:", "surname")
@Html.TextBox("surname", surname, new { maxlength = "50" } )
</p>
<p>
@Html.Label("Name: ", "name")
@Html.TextBox("name", name, new { maxlength = "50" } )
@Html.ValidationMessage("address1")
</p>
<p>
@Html.Label("Email Address: ", "email")
@Html.TextBox("email", email, new { maxlength = "50" } )
@Html.ValidationMessage("town")
</p>
<p>
@Html.Label("Arrival Date: ", "arrivalDate")
@Html.TextBox("arrivalDate", arrivalDate.ToShortDateString())
@Html.ValidationMessage("arrivalDate")
</p>
<p>
@Html.Label("Departure Date: ", "departureDate")
@Html.TextBox("departureDate", departureDate.ToShortDateString())
@Html.ValidationMessage("departureDate")
</p>
<p>
@Html.Label("City: ", "city")
@Html.TextBox("city", city, new { maxlength = "20" } )
</p>
<p>
@Html.Label("Country: ", "country")
@Html.TextBox("country", country, new { maxlength = "50" } )
</p>
<p>
@Html.Label("Nationality: ", "nationality")
@Html.TextBox("nationality", nationality, new { maxlength = "50" } )
</p>
<p>
@Html.Label("Passport No: ", "passportno")
@Html.TextBox("passportno", passportno, new { maxlength = "50" } )
</p>
<p>
@Html.Label("Occupation: ", "occupation")
@Html.TextBox("occupation", occupation, new { maxlength = "50" } )
</p>
<p>
@Html.Label("PaymentMethod: ", "paymentmethod")
@{
var paymentmethodList = new List<SelectListItem>()
{
new SelectListItem { Value = "cas", Text = "Cash" },
new SelectListItem { Value = "depos", Text = "Bank Deposit" },
};
}
@Html.DropDownList("paymentmethod", "Not selected", paymentmethodList, paymentmethod, null)
</p>
<h2>Confirm Reservation</h2>
<p>
<input type="submit" value="Place Reservation"/>
</p>
</form>
The query should be -查询应该是 -
...
"Nationality, [Passport No], Occupation
...
If column name has spaces, it need to be inside square brackets - [xxx]
.如果列名有空格,它需要在方括号内 - [xxx]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.