0

我正在尝试批准文件,下面是我做的按钮中的代码,
但这里会发生条件错误..任何人告诉我下面代码中的错误在哪里。是否有括号问题或其他问题????

代码

 protected void Button1_Click(object sender, EventArgs e)
    {

             string connStr = 
             ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
        SqlConnection mySQLconnection = new SqlConnection(connStr);
        if (mySQLconnection.State == ConnectionState.Closed)
        {
            mySQLconnection.Open();
        }


           for (int i = 0; i < Repeater2.Items.Count; i++)
        {
            DropDownList DropDownListcontrol = 
           ((DropDownList)Repeater2.Items[i].FindControl("DropDownList4"));
            Label DocId = ((Label)Repeater2.Items[i].FindControl("DocId"));


                        SqlCommand cmd = new SqlCommand("approveddd",mySQLconnection);
                        cmd.CommandType = CommandType.StoredProcedure;

                       cmd.Parameters.Add("@DocID", SqlDbType.Int).Value =
                            Convert.ToInt32((DocID.Text));

                        cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value =
                            Convert.ToInt32(DropDownListcontrol.SelectedValue);
                        cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value 
                     = (Session["Login2"]);

                        cmd.ExecuteNonQuery();

                        DMSLIB.Doc myDoc = new DMSLIB.Doc();
                        myDoc.MarkDocAs(Convert.ToInt16(DocId.Text),
                            Convert.ToInt32(DropDownListcontrol.SelectedValue));
                    }

                    else
                    {
                        apfi.Text = "Error";
                    }
                  if (mySQLconnection.State == ConnectionState.Open)
               {
                  mySQLconnection.Close();
                }
                }

块中出现错误else

    Invalid expression term 'else'
; expected  
4

2 回答 2

3

您必须遵循 Microsoft指南。它应该是这样的:

if(condition)
{
}
else
{
}

不像这样

  if(condition)
     {
     }
  for(...........)
     {
     }
  else
     {
     }
于 2013-11-14T11:25:06.363 回答
2

你放错地方了。改变你的 for 循环。因为你有

if()
{
}
for()
{
}
else// belongs to where?
{
}
于 2013-11-14T11:22:17.360 回答