错误编号 1。当我使用调试时,在按钮单击事件时,它在第一行显示黄线,然后被跳过我不知道如何,但它被跳过了



第一行它显示黄线,然后它被跳过返回我不知道如何?这是否意味着它没有显示取值?

private void btnsave_Click(object sender, EventArgs e)
{
    if (cmbxschl.SelectedIndex == 0)
    {
        lblmsg.Text = "Please Select School Name";
        lblmsg.ForeColor = System.Drawing.Color.Red;
        lblmsg.Visible = true;
        cmbxschl.Focus();
        return;
    }
    if (txtcls.Text.Trim().ToString() == "")
    {
        lblmsg.Text = "Please Enter Class Name";
        lblmsg.ForeColor = System.Drawing.Color.Red;
        lblmsg.Visible = true;
        txtcls.Focus();
        return;
    }
    save();
}

然后返回到另一个cs文件

public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)        
{
    if (connection == null) 
         throw new ArgumentNullException("connection");
     // Create a command and prepare it for execution
     SqlCommand cmd = new SqlCommand();
     bool mustCloseConnection = false;
     PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection);
     // Finally, execute the command
     int retval = cmd.ExecuteNonQuery(); //Showing error in this line saying that error converting nvarchar to int
     // Detach the SqlParameters from the command object, so they can be used again
        cmd.Parameters.Clear();
     if (mustCloseConnection)
            connection.Close();
     return retval;
}

如果跳过一行,则表示没有执行。最有可能的是,调试器向您显示它正在评估IF语句,并且因为它评估为false,所以它跳过了IF (true) ...部分并继续。

最新更新