简体   繁体   English

'GROUP 附近的语法不正确,当它是不正确的语法时是什么意思?

[英]'Incorrect syntax near GROUP, What does it mean when it is an incorrect syntax?

I am creating a form that I can add a menu item to display All Suppliers and Suppliers Quantity by Part number.我正在创建一个表单,我可以添加一个菜单项以按零件编号显示所有供应商和供应商数量。 So I got ReportSupplierDisplayALl to work when I ran.所以我在跑步时让 ReportSupplierDisplayALl 工作。 But When I try to run the form for the ReportSuppliersDisplayByPartnumber because When I enter the SupplierID and when I did it threw an exception.但是当我尝试运行 ReportSuppliersDisplayByPartnumber 的表单时,因为当我输入供应商 ID 时,它抛出了异常。 When it throws an exception, what does it mean by incorrect syntax?当它抛出异常时,不正确的语法是什么意思?

    public DataTable DisplaySupplierByPartNumber(string PartNumber)
    {
        // Add using System.Data

        string queryString = "SELECT Suppliers.SupplierName, Suppliers.Email, Parts.PartName, SUM(Inventory.Quantity) AS SumOfQuantity, PartNumber " +
        "FROM ((Suppliers INNER JOIN Parts ON Suppliers.SupplierID = Parts.Supplier) INNER JOIN Inventory ON Parts.PartNumber = Inventory.PartNumber " +
        "INNER JOIN Employees ON Inventory.EmpID = Employees.EmpID " +
        "GROUP BY Suppliers.SupplierName, Suppliers.Email, Parts.PartName, Parts.PartNumber " +
        "HAVING Parts.PartNumber = @PartNumber " +
        "ORDER BY Suppliers.SupplierName ";

        using (SqlConnection con = new SqlConnection(_strCon))
        {
            try
            {
                SqlCommand command = new SqlCommand(queryString, con);
                command.Parameters.AddWithValue("@PartNumber", PartNumber );
                con.Open();
                SqlDataReader reader = command.ExecuteReader();
                DataTable theTable = new DataTable();
                theTable.Load(reader);
                return theTable;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

enter image description here在此处输入图片说明

enter image description here在此处输入图片说明

Don't use "" For String use @ "Your Query And Make Sure You get all bracket correct" also change element take part number first then use your aggerate function不要使用“”对于字符串使用@“你的查询并确保你得到所有括号正确”也先改变元素取零件号然后使用你的aggate函数

string queryString = @"SELECT S.SupplierName, S.Email, P.PartName, SUM(Inventory. Quantity) AS SumOfQuantity FROM Suppliers as s
INNER JOIN Parts as p on P.SupplierId=P.SupplierId
INNER JOIN Inventory ON Parts.PartNumber = Inventory.PartNumber 
INNER JOIN Employees ON Inventory.EmpID = Employees.EmpID 
GROUP BY S.SupplierName, S.Email, P.PartName, P.PartNumber 
HAVING Parts.PartNumber = @PartNumber
ORDER BY S.SupplierName"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM