简体   繁体   English

谁能帮我解决这个数据库查询错误?

[英]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.

相关问题 INSERT INTO语句中的语法错误。 谁能帮我这个? - Syntax error in INSERT INTO statement. Can anyone help me with this? 基础设施错误,请有人帮我解决这个问题 - Infragistics Error,, Please anyone help me out on this 谁能帮我这个StackOverFlow.Exception吗? - Can anyone help me with this StackOverFlow.Exception? 谁能帮我Linq分拣 - Can anyone help me with Linq Sorting 谁能帮我解决 loadingSceneIndex 问题 - Can anyone help me with the loadingSceneIndex issue 我在 Windows 窗体应用程序中遇到以下错误? 任何人都可以帮助解决它 - I am facing with the following error in Windows Form Application ? Can anyone help to resolve it ASP.NET MVC 在进行聚合时抛出错误 - 任何人都可以帮助我吗? - ASP.NET MVC is throwing an error while doing aggregation - can anyone help me? mscorlib.dll 中发生了类型为“System.FormatException”的未处理异常 谁能帮我解决这个错误? - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Can anyone help me with this error? Net5.0 Razor 页面 CRUD 删除错误,谁能帮我解决这个问题? - Net5.0 Razor Pages CRUD Delete Error, Can anyone help me with this? 谁能帮我制作一个朝特定角度旋转的脚本 - Can anyone help me make a script that rotates towards a specific angle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM