谁能帮助我解决此数据库查询错误?

问题描述 投票:1回答: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> 
c# asp.net razor webmatrix
1个回答
2
投票

查询应为-

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

如果列名包含空格,则必须在方括号内-[xxx]

© www.soinside.com 2019 - 2024. All rights reserved.