简体   繁体   English

Visual Studio C# 不识别右大括号

[英]Visual Studio C# not identifying closing braces

I'm working with Visual Studio, making a .CSHTML web page.我正在使用 Visual Studio,制作一个 .CSHTML 网页。 The code was working code.该代码是工作代码。 Through some unknown edit?通过一些未知的编辑? or bug?(unlikely) Visual studio will not recognize the last set of {}.或错误?(不太可能)Visual Studio 将无法识别最后一组 {}。 The ones that start with @{ C# code here以@{ 开头的 C# 代码在这里

} }

Compiler Error: "Parser Error Message: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.编译器错误:“解析器错误消息:代码块缺少结束的“}”字符。确保此块中的所有“{”字符都具有匹配的“}”字符,并且没有“}”字符被解释为标记。

Source Error:源错误:

Line 2:第 2 行:
Line 3:第 3 行:
Line 4: @{ Line 5: var db = Database.Open("DevDbCS");第 4 行:@{ 第 5 行:var db = Database.Open("DevDbCS"); Line 6:第 6 行:
"

I have copy and pasted my code to notepad ++ that highlights the corresponding bracket if I select one.我已将我的代码复制并粘贴到记事本++,如果我选择一个,它会突出显示相应的括号。 I have confirmed that all brakes open and close correctly.我已确认所有制动器都正确打开和关闭。 I even dropped it into Processing, (wont compile) but it says all good too.我什至把它放到了 Processing 中,(不会编译)但它也说一切都很好。

@{
        var db = Database.Open("DevDbCS");

        var selectThorneID = "SELECT ThorneID, Status FROM Batch_Record WHERE Status = 'ACTIVE' ORDER BY ThorneID ASC";

        //Variables
        var ThorneID = " ";
        var frmInsertV = "";
        var frmInsert = "";
        var frmUpdate = "";
        var StartUnits = "";
        var EndUnits = "";
        var yield = "";
        var formValues = new double[29];//array for holding results from Query
        var QC = "";
        int RecordCount = 0;

        var sqlfrmValues = (db.Query("SELECT * FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'")).Cast<DynamicRecord>().ToArray();


        if (IsPost)
        {

            switch (Request.Form["userInput"])
            {
                case "Submit":
                    ThorneID = Request.Form["ThorneID"];
                    StartUnits = Request.Form["s12"];
                    EndUnits = Request.Form["s15"];
                    yield = Request.Form["s17"];
                    QC = Request.Form["QC"];

                    //Set to zero to avoid trying to put nulls in DB
                    if (Request.Form["s12"] == null)
                    {
                        StartUnits = "0";
                    }
                    else
                    {
                        StartUnits = Request.Form["s12"];
                    }

                    if (Request.Form["s15"] == null)
                    {
                        EndUnits = "0";
                    }
                    else
                    {
                        EndUnits = Request.Form["s15"];
                    }

                    if (Request.Form["s17"] == null)
                    {
                        yield = "0";
                    }
                    else {
                        yield = Request.Form["s17"];
                    }

                    for (int i = 1; i <= 26; i++)
                    {
                        //set to 1 to keep NaN from appearing, cant divide by zero
                        var itemStr = "var" + i.ToString();
                        var rfTemp = "";
                        if (Request.Form[itemStr] == null)
                        {
                            rfTemp = "0";
                            if (i == 3)
                            {
                                rfTemp = "1";
                            }
                            if (i == 10)
                            {
                                rfTemp = "1";
                            }
                            if (i == 16)
                            {
                                rfTemp = "1";
                            }

                        }
                        else
                        {
                            rfTemp = Request.Form[itemStr];
                        }

                        //put commas after 1st variable in the string for SQL
                        if (i != 1)
                        {
                            frmUpdate += ", ";
                            frmInsert += ", ";
                            frmInsertV += ", ";
                        }


                        frmUpdate += "s" + i + "= " + rfTemp;
                        frmInsertV += "s" + i;
                        frmInsert += rfTemp;

                    }

                    var UPSERTcommand = "IF EXISTS (SELECT * FROM YieldEncap WHERE ThorneID = '" + ThorneID + "') "
                                        + "UPDATE YieldEncap SET " + frmUpdate + ", QC='" + QC + "' "
                                        + "WHERE ThorneID = '" + ThorneID + "' "
                                        + "ELSE "
                                        + "INSERT INTO YieldEncap (ThorneID, QC, " + frmInsertV + ") "
                                        + "VALUES (" + ThorneID + ", '" + QC + "', " + frmInsert + ")";
                    db.Execute(UPSERTcommand);


                    UPSERTcommand = "IF EXISTS (SELECT * FROM BR_Details_Yield WHERE ThorneID = '" + ThorneID + "') "
                                       + "UPDATE BR_Details_Yield SET Department = 'Encap', Units = 'g', StartUnits = '" + StartUnits + "', EndUnits = '" + EndUnits + "', Yield = '" + yield + "' "
                                       + "WHERE ThorneID = '" + ThorneID + "' "
                                       + "ELSE "
                                       + "INSERT INTO BR_Details_Yield (Department, Units, StartUnits, EndUnits, Yield) "
                                       + "VALUES ('Encap', 'Bottles', " + StartUnits + ", " + EndUnits + ", " + yield + ")";
                    db.Execute(UPSERTcommand);
                    UPSERTcommand = "";

                    sqlfrmValues = (db.Query("SELECT * FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'")).Cast<DynamicRecord>().ToArray();
                    RecordCount = (int)db.QueryValue("SELECT COUNT(*) FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'");

                    //read out the values from sqlfrmValues and place them in an array
                    if (RecordCount > 0)
                    {
                        for (int i = 1; i <= 26; i++)
                        {
                            if (sqlfrmValues[0][i] != null)
                            {
                                formValues[i] = Convert.ToDouble(sqlfrmValues[0][i]);
                            }
                            else
                            {
                                formValues[i] = 0;
                            }

                        }
                        QC = Convert.ToString(sqlfrmValues[0][27]);
                    }
                    else
                    {
                        formValues[2] = 1;
                        formValues[10] = 1;
                        formValues[16] = 1;
                        formValues[19] = 1;
                    }

                    break;

                default:
                    ThorneID = Request.Form["ThorneID"];

                    sqlfrmValues = (db.Query("SELECT * FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'")).Cast<DynamicRecord>().ToArray();
                    var RecordCount2 = (db.Query("SELECT COUNT(*) FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'").Cast<DynamicRecord>().ToArray();

                    if (RecordCount[0][0] > 0)
                    {
                        for (int i = 1; i <= 26; i++)
                        {
                            if (sqlfrmValues[0][i] != null)
                            {
                                formValues[i] = Convert.ToDouble(sqlfrmValues[0][i]);
                            }
                            else
                            {
                                formValues[i] = 0;
                            }

                        }
                        QC = Convert.ToString(sqlfrmValues[0][27]);
                    }
                    else
                    {
                        formValues[6] = 1;
                        formValues[8] = 1;
                        formValues[11] = 1;
                        formValues[24] = 1;
                    }
                    //lookup for previous worksheet. Starting point value
                    //var sqlMixing = (db.Query("SELECT * FROM YieldMixing WHERE ThorneID = '" + ThorneID + "'")).Cast<DynamicRecord>().ToArray();
                    //var sqlMixingRecordCount = (int)db.QueryValue("SELECT COUNT(*) FROM YieldMixing WHERE ThorneID = '" + ThorneID + "'");
                    //if (sqlMixingRecordCount > 0)
                    //{

                    //    var temp = Convert.ToDouble(sqlfrmValues[0][1]);
                    //    formValues[1] = Convert.ToDouble(sqlMixing[0][1]);

                    //}

                    var sqlMixing = (db.Query("SELECT * FROM YieldMixing WHERE ThorneID = '" + ThorneID + "'")).Cast<DynamicRecord>().ToArray();
                    RecordCount = (int)db.QueryValue("SELECT COUNT(*) FROM YieldMixing WHERE ThorneID = '" + ThorneID + "'");
                    if (RecordCount > 0)
                    {
                        formValues[24] = Convert.ToDouble(sqlMixing[0][2]);
                        formValues[24] = formValues[24] * 1000;
                    }

                    break;

            }

        }
    }

When it gets to my !DOCTYPE html it tells me "The type or namespace name 'DOCTYPE' could not be could not be found....) Likely because it cant figure out where the closing brace is.当它到达我的 !DOCTYPE html 时,它告诉我“找不到类型或命名空间名称 'DOCTYPE'....)可能是因为它无法弄清楚右括号在哪里。

Where have I gone wrong?我哪里错了? It is very frustrating that the compilers message isnt being helpful because all the braces are correct!非常令人沮丧的是,编译器消息没有帮助,因为所有大括号都是正确的!

try to remove the opening parenthesis between the equal sign and the db variable in this line:尝试删除此行中等号和 db 变量之间的左括号:

var RecordCount2 = (db.Query ....

This doesn't have a matching closing parenthesis.这没有匹配的右括号。 Because of that the compiler can't match the curly braces afterwards to the opening ones and shows a misleading error因此,编译器无法将后面的大括号与开头的大括号匹配,并显示误导性错误

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

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