1

実行すると、次のエラー メッセージが表示されます。

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 ]

ソース エラー:

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,

以下に私のコードを示します。

@{
    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> 
4

1 に答える 1

2

クエリは-

...
"Nationality, [Passport No], Occupation
...

列名にスペースが含まれる場合は、角かっこで囲む必要があります - [xxx].

于 2013-07-12T21:56:36.530 に答える