Visual Studio C#无法识别结束括号

时间:2016-03-18 18:35:04

标签: c# visual-studio visual-studio-2012 razor

我正在使用Visual Studio制作.CSHTML网页。 代码是工作代码。通过一些未知的编辑?还是虫子?(不太可能) Visual Studio无法识别最后一组{}。  那些开始的 @ {C#代码在这里

}

编译器错误: "解析器错误消息:代码块缺少关闭"}"字符。确保你有匹配的"}"所有" {"这个区块内的字符,并没有"}"字符被解释为标记。

来源错误:

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

我已将我的代码复制并粘贴到记事本++中,如果我选择了一个,则会突出显示相应的括号。我已确认所有制动器都正确打开和关闭。我甚至将它放入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;

            }

        }
    }

当它到达我的!DOCTYPE html时,它告诉我&#34;类型或命名空间名称&#39; DOCTYPE&#39;无法找到....) 可能是因为它无法弄清楚闭合支架的位置。

我哪里出错了?编译器消息没有帮助是非常令人沮丧的,因为所有的括号都是正确的!

1 个答案:

答案 0 :(得分:3)

尝试删除此行中等号和db变量之间的左括号:

var RecordCount2 = (db.Query ....

这没有匹配的右括号。因此,编译器之后不能将大括号与开头大括号相匹配,并显示误导性错误